5 <title>jQuery UI Draggable - Constrain movement</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.9.1.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">
14 .draggable { width: 90px; height: 90px; padding: 0.5em; float: left; margin: 0 10px 10px 0; }
15 #draggable, #draggable2 { margin-bottom:20px; }
16 #draggable { cursor: n-resize; }
17 #draggable2 { cursor: e-resize; }
18 #containment-wrapper { width: 95%; height:150px; border:2px solid #ccc; padding: 10px; }
23 $( "#draggable" ).draggable({ axis: "y" });
24 $( "#draggable2" ).draggable({ axis: "x" });
26 $( "#draggable3" ).draggable({ containment: "#containment-wrapper", scroll: false });
27 $( "#draggable5" ).draggable({ containment: "parent" });
33 <h3>Constrain movement along an axis:</h3>
35 <div id="draggable" class="draggable ui-widget-content">
36 <p>I can be dragged only vertically</p>
39 <div id="draggable2" class="draggable ui-widget-content">
40 <p>I can be dragged only horizontally</p>
43 <h3>Or to within another DOM element:</h3>
44 <div id="containment-wrapper">
45 <div id="draggable3" class="draggable ui-widget-content">
46 <p>I'm contained within the box</p>
49 <div class="draggable ui-widget-content">
50 <p id="draggable5" class="ui-widget-header">I'm contained within my parent</p>
54 <div class="demo-description">
55 <p>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.'</p>