5
<title>Example: Drag - Constrained to a Region</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: Drag - Constrained to a Region</h1>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"><div class="intro">
23
<p>This example shows how to constrain a draggable Node to another Node's region.</p>
40
border: 1px solid black;
47
background-color: #004C6D;
48
border: 1px solid black;
52
background-color: #CDCDCD;
53
border: 1px solid black;
57
background-color: #8DD5E7;
58
border: 1px solid black;
62
background-color: #8DD5E7;
69
background-color: #CDCDCD;
76
background-color: #004C6D;
83
<div id="dd-demo-canvas1">
84
<div id="dd-demo-canvas2">
85
<div id="dd-demo-canvas3">
86
<div id="dd-demo-1" class="dd-demo"><div>1</div></div>
87
<div id="dd-demo-2" class="dd-demo"><div>2</div></div>
88
<div id="dd-demo-3" class="dd-demo"><div>3</div></div>
94
YUI().use('dd-constrain', function(Y) {
95
var dd1 = new Y.DD.Drag({
97
}).plug(Y.Plugin.DDConstrained, {
98
constrain2node: '#dd-demo-canvas3'
101
var dd2 = new Y.DD.Drag({
103
}).plug(Y.Plugin.DDConstrained, {
104
constrain2node: '#dd-demo-canvas2'
107
var dd3 = new Y.DD.Drag({
109
}).plug(Y.Plugin.DDConstrained, {
110
constrain2node: '#dd-demo-canvas1'
118
<h3 id="setting-up-the-node">Setting up the Node</h3>
119
<p>First we need to create the HTML structure used in this example.</p>
121
<pre class="code prettyprint"><div id="dd-demo-canvas1">
122
<div id="dd-demo-canvas2">
123
<div id="dd-demo-canvas3">
124
<div id="dd-demo-1" class="dd-demo"><div>1</div></div>
125
<div id="dd-demo-2" class="dd-demo"><div>2</div></div>
126
<div id="dd-demo-3" class="dd-demo"><div>3</div></div>
129
</div></pre>
132
<p>Now we give the Nodes some CSS to make them visible.</p>
134
<pre class="code prettyprint">.dd-demo {
146
border: 1px solid black;
153
background-color: #004C6D;
154
border: 1px solid black;
158
background-color: #CDCDCD;
159
border: 1px solid black;
163
background-color: #8DD5E7;
164
border: 1px solid black;
168
background-color: #8DD5E7;
175
background-color: #CDCDCD;
182
background-color: #004C6D;
188
<h3 id="setting-up-the-yui-instance">Setting up the YUI Instance</h3>
189
<p>Now we need to create our YUI instance and tell it to load the <code>dd-constrain</code> module (that will load the dd-ddm and dd-drag modules too).</p>
191
<pre class="code prettyprint">YUI().use('dd-constrain');</pre>
194
<h3 id="making-the-nodes-draggable">Making the Nodes draggable</h3>
195
<p>Now that we have a YUI instance with the <code>dd-constrain</code> module, we need to instantiate the <code>Drag</code> instance on the Nodes.</p>
197
<pre class="code prettyprint">YUI().use('dd-constrain', function(Y) {
198
var dd1 = new Y.DD.Drag({
199
node: '#dd-demo-1'
202
var dd2 = new Y.DD.Drag({
203
node: '#dd-demo-2'
206
var dd3 = new Y.DD.Drag({
207
node: '#dd-demo-3'
212
<h3 id="constrain-the-nodes-to-other-nodes">Constrain the Nodes to other Nodes</h3>
213
<p>Now that we have the Nodes draggable, we need to constrain them. We can do this by plugging the <code>DDConstrained</code> on to the <code>Drag</code> instance and passing it a config option called <code>constrain2node</code> and giving it a selector string of the Node we want to constrain to.</p>
215
<pre class="code prettyprint">YUI().use('dd-constrain', function(Y) {
216
var dd1 = new Y.DD.Drag({
217
node: '#dd-demo-1'
218
}).plug(Y.Plugin.DDConstrained, {
219
constrain2node: '#dd-demo-canvas3'
222
var dd2 = new Y.DD.Drag({
223
node: '#dd-demo-2'
224
}).plug(Y.Plugin.DDConstrained, {
225
constrain2node: '#dd-demo-canvas2'
228
var dd3 = new Y.DD.Drag({
229
node: '#dd-demo-3'
230
}).plug(Y.Plugin.DDConstrained, {
231
constrain2node: '#dd-demo-canvas1'
238
<div id="sidebar" class="yui3-u">
240
<div id="toc" class="sidebox">
242
<h2 class="no-toc">Table of Contents</h2>
248
<a href="#setting-up-the-node">Setting up the Node</a>
251
<a href="#setting-up-the-yui-instance">Setting up the YUI Instance</a>
254
<a href="#making-the-nodes-draggable">Making the Nodes draggable</a>
257
<a href="#constrain-the-nodes-to-other-nodes">Constrain the Nodes to other Nodes</a>
265
<div class="sidebox">
267
<h2 class="no-toc">Examples</h2>
271
<ul class="examples">
274
<li data-description="A simple drag interaction that doesn't require a drop interaction.">
275
<a href="simple-drag.html">Simple Drag</a>
280
<li data-description="How to apply the Drag Plugin to a node.">
281
<a href="drag-plugin.html">Drag - Node plugin</a>
286
<li data-description="A simple proxy drag interaction that doesn't require a drop interaction.">
287
<a href="proxy-drag.html">Drag - Proxy</a>
292
<li data-description="How to constrain a draggable Node to another Node's region.">
293
<a href="constrained-drag.html">Drag - Constrained to a Region</a>
298
<li data-description="Using interaction groups, this example demonstrates how to tie into the Drag & Drop Utility's interesting moments to provide visual affordances for the current drag operation.">
299
<a href="groups-drag.html">Drag - Interaction Groups</a>
304
<li data-description="The use of the drag shim when dragging nodes over other troublesome nodes.">
305
<a href="shim-drag.html">Using the Drag Shim</a>
310
<li data-description="How to use the Drop Target events to code your application.">
311
<a href="drop-code.html">Using Drop Based Coding</a>
316
<li data-description="How you can use the DD Scroll plugin to scroll the browser window as you drag.">
317
<a href="winscroll.html">Window Scrolling</a>
322
<li data-description="How to use DD.Delegate to create a scalable solution which supports multiple draggable items.">
323
<a href="delegate.html">Drag Delegation</a>
328
<li data-description="Using DD.Delegate to support dragging multiple items and dropping them onto a Drop Target.">
329
<a href="delegate-drop.html">Drag Delegation with a Drop Target</a>
334
<li data-description="How to use Drag plugins with a DD Delegate based solution.">
335
<a href="delegate-plugins.html">Using Drag Plugins with Delegate</a>
340
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling.">
341
<a href="list-drag.html">List Reorder w/Bubbling</a>
346
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling and Node Scrolling.">
347
<a href="scroll-list.html">List Reorder w/Scrolling</a>
352
<li data-description="How to make an animated node a Drop target.">
353
<a href="anim-drop.html">Animated Drop Targets</a>
358
<li data-description="Example Photo Browser application.">
359
<a href="photo-browser.html">Photo Browser</a>
364
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation.">
365
<a href="portal-drag.html">Portal Style Example</a>
379
<div class="sidebox">
381
<h2 class="no-toc">Examples That Use This Component</h2>
385
<ul class="examples">
420
<li data-description="Working with multiple YUI instances.">
421
<a href="../yui/yui-multi.html">Multiple Instances</a>
426
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input">
427
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a>
439
<script src="../assets/vendor/prettify/prettify-min.js"></script>
440
<script>prettyPrint();</script>