Debian Codegraph @

demos/draggable/snap-to.html

raw
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <title>jQuery UI Draggable - Snap to element or grid</title>
7 <link rel="stylesheet" href="../../themes/base/all.css">
8 <link rel="stylesheet" href="../demos.css">
9 <style>
10 .draggable { width: 90px; height: 80px; padding: 5px; float: left; margin: 0 10px 10px 0; font-size: .9em; }
11 .ui-widget-header p, .ui-widget-content p { margin: 0; }
12 #snaptarget { height: 140px; }
13 </style>
14 <script src="../../external/requirejs/require.js"></script>
15 <script src="../bootstrap.js">
16 $( "#draggable" ).draggable({ snap: true });
17 $( "#draggable2" ).draggable({ snap: ".ui-widget-header" });
18 $( "#draggable3" ).draggable({ snap: ".ui-widget-header", snapMode: "outer" });
19 $( "#draggable4" ).draggable({ grid: [ 20, 20 ] });
20 $( "#draggable5" ).draggable({ grid: [ 80, 80 ] });
21 </script>
22 </head>
23 <body>
24
25 <div id="snaptarget" class="ui-widget-header">
26 <p>I'm a snap target</p>
27 </div>
28
29 <br style="clear:both" />
30
31 <div id="draggable" class="draggable ui-widget-content">
32 <p>Default (snap: true), snaps to all other draggable elements</p>
33 </div>
34
35 <div id="draggable2" class="draggable ui-widget-content">
36 <p>I only snap to the big box</p>
37 </div>
38
39 <div id="draggable3" class="draggable ui-widget-content">
40 <p>I only snap to the outer edges of the big box</p>
41 </div>
42
43 <div id="draggable4" class="draggable ui-widget-content">
44 <p>I snap to a 20 x 20 grid</p>
45 </div>
46
47 <div id="draggable5" class="draggable ui-widget-content">
48 <p>I snap to a 80 x 80 grid</p>
49 </div>
50
51 <div class="demo-description">
52 <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>
53 <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>
54 </div>
55 </body>
56 </html>