1 | <!doctype html>
|
---|
2 | <html lang="en">
|
---|
3 | <head>
|
---|
4 | <title>jQuery UI Draggable - Constrain movement</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: 90px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
|
---|
14 | #draggable, #draggable2 { margin-bottom:20px; }
|
---|
15 | #draggable { cursor: n-resize; }
|
---|
16 | #draggable2 { cursor: e-resize; }
|
---|
17 | #containment-wrapper { width: 95%; height:150px; border:2px solid #ccc; padding: 10px;}
|
---|
18 | </style>
|
---|
19 | <script type="text/javascript">
|
---|
20 | $(function() {
|
---|
21 | $("#draggable").draggable({ axis: 'y' });
|
---|
22 | $("#draggable2").draggable({ axis: 'x' });
|
---|
23 |
|
---|
24 | $("#draggable3").draggable({ containment: '#containment-wrapper', scroll: false });
|
---|
25 | $("#draggable4").draggable({ containment: '#demo-frame' });
|
---|
26 | $("#draggable5").draggable({ containment: 'parent' });
|
---|
27 |
|
---|
28 | });
|
---|
29 | </script>
|
---|
30 | </head>
|
---|
31 | <body>
|
---|
32 | <div class="demo">
|
---|
33 |
|
---|
34 | <h3 class="docs">Constrain movement along an axis:</h3>
|
---|
35 |
|
---|
36 | <div id="draggable" class="draggable ui-widget-content">
|
---|
37 | <p>I can be dragged only vertically</p>
|
---|
38 | </div>
|
---|
39 |
|
---|
40 | <div id="draggable2" class="draggable ui-widget-content">
|
---|
41 | <p>I can be dragged only horizontally</p>
|
---|
42 | </div>
|
---|
43 |
|
---|
44 | <h3 class="docs">Or to within another DOM element:</h3>
|
---|
45 | <div id="containment-wrapper">
|
---|
46 | <div id="draggable3" class="draggable ui-widget-content">
|
---|
47 | <p>I'm contained within the box</p>
|
---|
48 | </div>
|
---|
49 |
|
---|
50 | <div id="draggable4" class="draggable ui-widget-content">
|
---|
51 | <p>I'm contained within the box's parent</p>
|
---|
52 | </div>
|
---|
53 |
|
---|
54 | <div class="draggable ui-widget-content">
|
---|
55 | <p id="draggable5" class="ui-widget-header">I'm contained within my parent</p>
|
---|
56 | </div>
|
---|
57 | </div>
|
---|
58 |
|
---|
59 | </div><!-- End demo -->
|
---|
60 |
|
---|
61 | <div class="demo-description">
|
---|
62 |
|
---|
63 | <p>
|
---|
64 | Constrain the movement of each draggable by defining the boundaries of the draggable area. Set the <code>axis</code> option to limit the draggable's path to the x- or y-axis, or use the <code>containment</code> option to specify a parent DOM element or a jQuery selector, like 'document.'
|
---|
65 | </p>
|
---|
66 |
|
---|
67 | </div><!-- End demo-description -->
|
---|
68 | </body>
|
---|
69 | </html>
|
---|