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