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 rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
|
---|
7 | <script src="../../jquery-1.6.2.js"></script>
|
---|
8 | <script src="../../ui/jquery.ui.core.js"></script>
|
---|
9 | <script src="../../ui/jquery.ui.widget.js"></script>
|
---|
10 | <script src="../../ui/jquery.ui.mouse.js"></script>
|
---|
11 | <script src="../../ui/jquery.ui.draggable.js"></script>
|
---|
12 | <link rel="stylesheet" href="../demos.css">
|
---|
13 | <style>
|
---|
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>
|
---|
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 |
|
---|
30 | <div class="demo">
|
---|
31 |
|
---|
32 | <div id="snaptarget" class="ui-widget-header">
|
---|
33 | <p>I'm a snap target</p>
|
---|
34 | </div>
|
---|
35 |
|
---|
36 | <br clear="both" />
|
---|
37 |
|
---|
38 | <div id="draggable" class="draggable ui-widget-content">
|
---|
39 | <p>Default (snap: true), snaps to all other draggable elements</p>
|
---|
40 | </div>
|
---|
41 |
|
---|
42 | <div id="draggable2" class="draggable ui-widget-content">
|
---|
43 | <p>I only snap to the big box</p>
|
---|
44 | </div>
|
---|
45 |
|
---|
46 | <div id="draggable3" class="draggable ui-widget-content">
|
---|
47 | <p>I only snap to the outer edges of the big box</p>
|
---|
48 | </div>
|
---|
49 |
|
---|
50 | <div id="draggable4" class="draggable ui-widget-content">
|
---|
51 | <p>I snap to a 20 x 20 grid</p>
|
---|
52 | </div>
|
---|
53 |
|
---|
54 | <div id="draggable5" class="draggable ui-widget-content">
|
---|
55 | <p>I snap to a 80 x 80 grid</p>
|
---|
56 | </div>
|
---|
57 |
|
---|
58 | </div><!-- End demo -->
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | <div class="demo-description">
|
---|
63 | <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>
|
---|
64 | <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>
|
---|
65 | </div><!-- End demo-description -->
|
---|
66 |
|
---|
67 | </body>
|
---|
68 | </html>
|
---|