|
1 <!DOCTYPE html> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="UTF-8" /> |
|
5 <title>jQuery UI Draggable - Snap to element or grid</title> |
|
6 <link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" /> |
|
7 <script type="text/javascript" src="../../jquery-1.4.2.js"></script> |
|
8 <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script> |
|
9 <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script> |
|
10 <script type="text/javascript" src="../../ui/jquery.ui.mouse.js"></script> |
|
11 <script type="text/javascript" src="../../ui/jquery.ui.draggable.js"></script> |
|
12 <link type="text/css" href="../demos.css" rel="stylesheet" /> |
|
13 <style type="text/css"> |
|
14 .draggable { width: 90px; height: 80px; padding: 5px; float: left; margin: 0 10px 10px 0; font-size: .9em; } |
|
15 .ui-widget-header p, .ui-widget-content p { margin: 0; } |
|
16 #snaptarget { height: 140px; } |
|
17 </style> |
|
18 <script type="text/javascript"> |
|
19 $(function() { |
|
20 $("#draggable").draggable({ snap: true }); |
|
21 $("#draggable2").draggable({ snap: '.ui-widget-header' }); |
|
22 $("#draggable3").draggable({ snap: '.ui-widget-header', snapMode: 'outer' }); |
|
23 $("#draggable4").draggable({ grid: [20,20] }); |
|
24 $("#draggable5").draggable({ grid: [80, 80] }); |
|
25 }); |
|
26 </script> |
|
27 </head> |
|
28 <body> |
|
29 <div class="demo"> |
|
30 |
|
31 <div id="snaptarget" class="ui-widget-header"> |
|
32 <p>I'm a snap target</p> |
|
33 </div> |
|
34 |
|
35 <br clear="both" /> |
|
36 |
|
37 <div id="draggable" class="draggable ui-widget-content"> |
|
38 <p>Default (snap: true), snaps to all other draggable elements</p> |
|
39 </div> |
|
40 |
|
41 <div id="draggable2" class="draggable ui-widget-content"> |
|
42 <p>I only snap to the big box</p> |
|
43 </div> |
|
44 |
|
45 <div id="draggable3" class="draggable ui-widget-content"> |
|
46 <p>I only snap to the outer edges of the big box</p> |
|
47 </div> |
|
48 |
|
49 <div id="draggable4" class="draggable ui-widget-content"> |
|
50 <p>I snap to a 20 x 20 grid</p> |
|
51 </div> |
|
52 |
|
53 <div id="draggable5" class="draggable ui-widget-content"> |
|
54 <p>I snap to a 80 x 80 grid</p> |
|
55 </div> |
|
56 |
|
57 </div><!-- End demo --> |
|
58 |
|
59 <div class="demo-description"> |
|
60 |
|
61 <p>Snap the draggable to the inner or outer boundaries of a DOM element. Use the <code>snap</code>, <code>snapMode</code> (inner, outer, both), and <code>snapTolerance</code> (distance in pixels the draggable must be from the element when snapping is invoked) options. </p> |
|
62 |
|
63 <p>Or snap the draggable to a grid. Set the dimensions of grid cells (height and width in pixels) with the <code>grid</code> option.</p> |
|
64 |
|
65 </div><!-- End demo-description --> |
|
66 |
|
67 |
|
68 |
|
69 </body> |
|
70 </html> |