|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Drag - Constrained to a Region</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Example: Drag - Constrained to a Region</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p>This example shows how to constrain a draggable Node to another Node's region.</p> |
|
|
32 |
</div> |
|
|
33 |
|
|
|
34 |
<div class="example"> |
|
|
35 |
<style> |
|
|
36 |
.dd-demo { |
|
|
37 |
position: relative; |
|
|
38 |
text-align: center; |
|
|
39 |
color: #fff; |
|
|
40 |
cursor: move; |
|
|
41 |
height: 60px; |
|
|
42 |
width: 60px; |
|
|
43 |
padding: 0; |
|
|
44 |
margin: 0; |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
.dd-demo div { |
|
|
48 |
border: 1px solid black; |
|
|
49 |
height: 58px; |
|
|
50 |
width: 58px; |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
#dd-demo-canvas1 { |
|
|
54 |
padding: 55px; |
|
|
55 |
background-color: #004C6D; |
|
|
56 |
border: 1px solid black; |
|
|
57 |
} |
|
|
58 |
#dd-demo-canvas2 { |
|
|
59 |
padding: 25px; |
|
|
60 |
background-color: #CDCDCD; |
|
|
61 |
border: 1px solid black; |
|
|
62 |
} |
|
|
63 |
#dd-demo-canvas3 { |
|
|
64 |
padding: 15px; |
|
|
65 |
background-color: #8DD5E7; |
|
|
66 |
border: 1px solid black; |
|
|
67 |
} |
|
|
68 |
|
|
|
69 |
#dd-demo-1 { |
|
|
70 |
background-color: #8DD5E7; |
|
|
71 |
top:5px; |
|
|
72 |
left:5px; |
|
|
73 |
color: #000; |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
#dd-demo-2 { |
|
|
77 |
background-color: #CDCDCD; |
|
|
78 |
top:50px; |
|
|
79 |
left:100px; |
|
|
80 |
color: #000; |
|
|
81 |
} |
|
|
82 |
|
|
|
83 |
#dd-demo-3 { |
|
|
84 |
background-color: #004C6D; |
|
|
85 |
top:-100px; |
|
|
86 |
left:200px; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
</style> |
|
|
90 |
|
|
|
91 |
<div id="dd-demo-canvas1"> |
|
|
92 |
<div id="dd-demo-canvas2"> |
|
|
93 |
<div id="dd-demo-canvas3"> |
|
|
94 |
<div id="dd-demo-1" class="dd-demo"><div>1</div></div> |
|
|
95 |
<div id="dd-demo-2" class="dd-demo"><div>2</div></div> |
|
|
96 |
<div id="dd-demo-3" class="dd-demo"><div>3</div></div> |
|
|
97 |
</div> |
|
|
98 |
</div> |
|
|
99 |
</div> |
|
|
100 |
|
|
|
101 |
<script> |
|
|
102 |
YUI().use('dd-constrain', function(Y) { |
|
|
103 |
var dd1 = new Y.DD.Drag({ |
|
|
104 |
node: '#dd-demo-1' |
|
|
105 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
106 |
constrain2node: '#dd-demo-canvas3' |
|
|
107 |
}); |
|
|
108 |
|
|
|
109 |
var dd2 = new Y.DD.Drag({ |
|
|
110 |
node: '#dd-demo-2' |
|
|
111 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
112 |
constrain2node: '#dd-demo-canvas2' |
|
|
113 |
}); |
|
|
114 |
|
|
|
115 |
var dd3 = new Y.DD.Drag({ |
|
|
116 |
node: '#dd-demo-3' |
|
|
117 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
118 |
constrain2node: '#dd-demo-canvas1' |
|
|
119 |
}); |
|
|
120 |
}); |
|
|
121 |
</script> |
|
|
122 |
|
|
|
123 |
|
|
|
124 |
</div> |
|
|
125 |
|
|
|
126 |
<h3 id="setting-up-the-node">Setting up the Node</h3> |
|
|
127 |
<p>First we need to create the HTML structure used in this example.</p> |
|
|
128 |
|
|
|
129 |
<pre class="code prettyprint"><div id="dd-demo-canvas1"> |
|
|
130 |
<div id="dd-demo-canvas2"> |
|
|
131 |
<div id="dd-demo-canvas3"> |
|
|
132 |
<div id="dd-demo-1" class="dd-demo"><div>1</div></div> |
|
|
133 |
<div id="dd-demo-2" class="dd-demo"><div>2</div></div> |
|
|
134 |
<div id="dd-demo-3" class="dd-demo"><div>3</div></div> |
|
|
135 |
</div> |
|
|
136 |
</div> |
|
|
137 |
</div></pre> |
|
|
138 |
|
|
|
139 |
|
|
|
140 |
<p>Now we give the Nodes some CSS to make them visible.</p> |
|
|
141 |
|
|
|
142 |
<pre class="code prettyprint">.dd-demo { |
|
|
143 |
position: relative; |
|
|
144 |
text-align: center; |
|
|
145 |
color: #fff; |
|
|
146 |
cursor: move; |
|
|
147 |
height: 60px; |
|
|
148 |
width: 60px; |
|
|
149 |
padding: 0; |
|
|
150 |
margin: 0; |
|
|
151 |
} |
|
|
152 |
|
|
|
153 |
.dd-demo div { |
|
|
154 |
border: 1px solid black; |
|
|
155 |
height: 58px; |
|
|
156 |
width: 58px; |
|
|
157 |
} |
|
|
158 |
|
|
|
159 |
#dd-demo-canvas1 { |
|
|
160 |
padding: 55px; |
|
|
161 |
background-color: #004C6D; |
|
|
162 |
border: 1px solid black; |
|
|
163 |
} |
|
|
164 |
#dd-demo-canvas2 { |
|
|
165 |
padding: 25px; |
|
|
166 |
background-color: #CDCDCD; |
|
|
167 |
border: 1px solid black; |
|
|
168 |
} |
|
|
169 |
#dd-demo-canvas3 { |
|
|
170 |
padding: 15px; |
|
|
171 |
background-color: #8DD5E7; |
|
|
172 |
border: 1px solid black; |
|
|
173 |
} |
|
|
174 |
|
|
|
175 |
#dd-demo-1 { |
|
|
176 |
background-color: #8DD5E7; |
|
|
177 |
top:5px; |
|
|
178 |
left:5px; |
|
|
179 |
color: #000; |
|
|
180 |
} |
|
|
181 |
|
|
|
182 |
#dd-demo-2 { |
|
|
183 |
background-color: #CDCDCD; |
|
|
184 |
top:50px; |
|
|
185 |
left:100px; |
|
|
186 |
color: #000; |
|
|
187 |
} |
|
|
188 |
|
|
|
189 |
#dd-demo-3 { |
|
|
190 |
background-color: #004C6D; |
|
|
191 |
top:-100px; |
|
|
192 |
left:200px; |
|
|
193 |
}</pre> |
|
|
194 |
|
|
|
195 |
|
|
|
196 |
<h3 id="setting-up-the-yui-instance">Setting up the YUI Instance</h3> |
|
|
197 |
<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> |
|
|
198 |
|
|
|
199 |
<pre class="code prettyprint">YUI().use('dd-constrain');</pre> |
|
|
200 |
|
|
|
201 |
|
|
|
202 |
<h3 id="making-the-nodes-draggable">Making the Nodes draggable</h3> |
|
|
203 |
<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> |
|
|
204 |
|
|
|
205 |
<pre class="code prettyprint">YUI().use('dd-constrain', function(Y) { |
|
|
206 |
var dd1 = new Y.DD.Drag({ |
|
|
207 |
node: '#dd-demo-1' |
|
|
208 |
}); |
|
|
209 |
|
|
|
210 |
var dd2 = new Y.DD.Drag({ |
|
|
211 |
node: '#dd-demo-2' |
|
|
212 |
}); |
|
|
213 |
|
|
|
214 |
var dd3 = new Y.DD.Drag({ |
|
|
215 |
node: '#dd-demo-3' |
|
|
216 |
}); |
|
|
217 |
});</pre> |
|
|
218 |
|
|
|
219 |
|
|
|
220 |
<h3 id="constrain-the-nodes-to-other-nodes">Constrain the Nodes to other Nodes</h3> |
|
|
221 |
<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> |
|
|
222 |
|
|
|
223 |
<pre class="code prettyprint">YUI().use('dd-constrain', function(Y) { |
|
|
224 |
var dd1 = new Y.DD.Drag({ |
|
|
225 |
node: '#dd-demo-1' |
|
|
226 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
227 |
constrain2node: '#dd-demo-canvas3' |
|
|
228 |
}); |
|
|
229 |
|
|
|
230 |
var dd2 = new Y.DD.Drag({ |
|
|
231 |
node: '#dd-demo-2' |
|
|
232 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
233 |
constrain2node: '#dd-demo-canvas2' |
|
|
234 |
}); |
|
|
235 |
|
|
|
236 |
var dd3 = new Y.DD.Drag({ |
|
|
237 |
node: '#dd-demo-3' |
|
|
238 |
}).plug(Y.Plugin.DDConstrained, { |
|
|
239 |
constrain2node: '#dd-demo-canvas1' |
|
|
240 |
}); |
|
|
241 |
});</pre> |
|
|
242 |
|
|
|
243 |
</div> |
|
|
244 |
</div> |
|
|
245 |
</div> |
|
|
246 |
|
|
|
247 |
<div class="yui3-u-1-4"> |
|
|
248 |
<div class="sidebar"> |
|
|
249 |
|
|
|
250 |
<div id="toc" class="sidebox"> |
|
|
251 |
<div class="hd"> |
|
|
252 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
253 |
</div> |
|
|
254 |
|
|
|
255 |
<div class="bd"> |
|
|
256 |
<ul class="toc"> |
|
|
257 |
<li> |
|
|
258 |
<a href="#setting-up-the-node">Setting up the Node</a> |
|
|
259 |
</li> |
|
|
260 |
<li> |
|
|
261 |
<a href="#setting-up-the-yui-instance">Setting up the YUI Instance</a> |
|
|
262 |
</li> |
|
|
263 |
<li> |
|
|
264 |
<a href="#making-the-nodes-draggable">Making the Nodes draggable</a> |
|
|
265 |
</li> |
|
|
266 |
<li> |
|
|
267 |
<a href="#constrain-the-nodes-to-other-nodes">Constrain the Nodes to other Nodes</a> |
|
|
268 |
</li> |
|
|
269 |
</ul> |
|
|
270 |
</div> |
|
|
271 |
</div> |
|
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
<div class="sidebox"> |
|
|
276 |
<div class="hd"> |
|
|
277 |
<h2 class="no-toc">Examples</h2> |
|
|
278 |
</div> |
|
|
279 |
|
|
|
280 |
<div class="bd"> |
|
|
281 |
<ul class="examples"> |
|
|
282 |
|
|
|
283 |
|
|
|
284 |
<li data-description="A simple drag interaction that doesn't require a drop interaction."> |
|
|
285 |
<a href="simple-drag.html">Simple Drag</a> |
|
|
286 |
</li> |
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
<li data-description="How to apply the Drag Plugin to a node."> |
|
|
291 |
<a href="drag-plugin.html">Drag - Node plugin</a> |
|
|
292 |
</li> |
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
<li data-description="A simple proxy drag interaction that doesn't require a drop interaction."> |
|
|
297 |
<a href="proxy-drag.html">Drag - Proxy</a> |
|
|
298 |
</li> |
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
<li data-description="How to constrain a draggable Node to another Node's region."> |
|
|
303 |
<a href="constrained-drag.html">Drag - Constrained to a Region</a> |
|
|
304 |
</li> |
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
<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."> |
|
|
309 |
<a href="groups-drag.html">Drag - Interaction Groups</a> |
|
|
310 |
</li> |
|
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
<li data-description="The use of the drag shim when dragging nodes over other troublesome nodes."> |
|
|
315 |
<a href="shim-drag.html">Using the Drag Shim</a> |
|
|
316 |
</li> |
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
<li data-description="How to use the Drop Target events to code your application."> |
|
|
321 |
<a href="drop-code.html">Using Drop Based Coding</a> |
|
|
322 |
</li> |
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
<li data-description="How you can use the DD Scroll plugin to scroll the browser window as you drag."> |
|
|
327 |
<a href="winscroll.html">Window Scrolling</a> |
|
|
328 |
</li> |
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
<li data-description="How to use DD.Delegate to create a scalable solution which supports multiple draggable items."> |
|
|
333 |
<a href="delegate.html">Drag Delegation</a> |
|
|
334 |
</li> |
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
<li data-description="Using DD.Delegate to support dragging multiple items and dropping them onto a Drop Target."> |
|
|
339 |
<a href="delegate-drop.html">Drag Delegation with a Drop Target</a> |
|
|
340 |
</li> |
|
|
341 |
|
|
|
342 |
|
|
|
343 |
|
|
|
344 |
<li data-description="How to use Drag plugins with a DD Delegate based solution."> |
|
|
345 |
<a href="delegate-plugins.html">Using Drag Plugins with Delegate</a> |
|
|
346 |
</li> |
|
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
|
350 |
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling."> |
|
|
351 |
<a href="list-drag.html">List Reorder w/Bubbling</a> |
|
|
352 |
</li> |
|
|
353 |
|
|
|
354 |
|
|
|
355 |
|
|
|
356 |
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling and Node Scrolling."> |
|
|
357 |
<a href="scroll-list.html">List Reorder w/Scrolling</a> |
|
|
358 |
</li> |
|
|
359 |
|
|
|
360 |
|
|
|
361 |
|
|
|
362 |
<li data-description="How to make an animated node a Drop target."> |
|
|
363 |
<a href="anim-drop.html">Animated Drop Targets</a> |
|
|
364 |
</li> |
|
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
|
368 |
<li data-description="Example Photo Browser application."> |
|
|
369 |
<a href="photo-browser.html">Photo Browser</a> |
|
|
370 |
</li> |
|
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
|
374 |
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
|
375 |
<a href="portal-drag.html">Portal Style Example</a> |
|
|
376 |
</li> |
|
|
377 |
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
</ul> |
|
|
384 |
</div> |
|
|
385 |
</div> |
|
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
<div class="sidebox"> |
|
|
390 |
<div class="hd"> |
|
|
391 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
392 |
</div> |
|
|
393 |
|
|
|
394 |
<div class="bd"> |
|
|
395 |
<ul class="examples"> |
|
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
<li data-description="Working with multiple YUI instances."> |
|
|
431 |
<a href="../yui/yui-multi.html">Multiple Instances</a> |
|
|
432 |
</li> |
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input"> |
|
|
437 |
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a> |
|
|
438 |
</li> |
|
|
439 |
|
|
|
440 |
|
|
|
441 |
</ul> |
|
|
442 |
</div> |
|
|
443 |
</div> |
|
|
444 |
|
|
|
445 |
</div> |
|
|
446 |
</div> |
|
|
447 |
</div> |
|
|
448 |
</div> |
|
|
449 |
|
|
|
450 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
451 |
<script>prettyPrint();</script> |
|
|
452 |
|
|
|
453 |
<script> |
|
|
454 |
YUI.Env.Tests = { |
|
|
455 |
examples: [], |
|
|
456 |
project: '../assets', |
|
|
457 |
assets: '../assets/dd', |
|
|
458 |
name: 'constrained-drag', |
|
|
459 |
title: 'Drag - Constrained to a Region', |
|
|
460 |
newWindow: '', |
|
|
461 |
auto: false |
|
|
462 |
}; |
|
|
463 |
YUI.Env.Tests.examples.push('simple-drag'); |
|
|
464 |
YUI.Env.Tests.examples.push('drag-plugin'); |
|
|
465 |
YUI.Env.Tests.examples.push('proxy-drag'); |
|
|
466 |
YUI.Env.Tests.examples.push('constrained-drag'); |
|
|
467 |
YUI.Env.Tests.examples.push('groups-drag'); |
|
|
468 |
YUI.Env.Tests.examples.push('shim-drag'); |
|
|
469 |
YUI.Env.Tests.examples.push('drop-code'); |
|
|
470 |
YUI.Env.Tests.examples.push('winscroll'); |
|
|
471 |
YUI.Env.Tests.examples.push('delegate'); |
|
|
472 |
YUI.Env.Tests.examples.push('delegate-drop'); |
|
|
473 |
YUI.Env.Tests.examples.push('delegate-plugins'); |
|
|
474 |
YUI.Env.Tests.examples.push('list-drag'); |
|
|
475 |
YUI.Env.Tests.examples.push('scroll-list'); |
|
|
476 |
YUI.Env.Tests.examples.push('anim-drop'); |
|
|
477 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
478 |
YUI.Env.Tests.examples.push('portal-drag'); |
|
|
479 |
YUI.Env.Tests.examples.push('yui-multi'); |
|
|
480 |
YUI.Env.Tests.examples.push('stylesheet-theme'); |
|
|
481 |
|
|
|
482 |
</script> |
|
|
483 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
484 |
|
|
|
485 |
|
|
|
486 |
|
|
|
487 |
</body> |
|
|
488 |
</html> |