40 |
aurelien |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
<head>
|
|
|
4 |
<meta charset="utf-8">
|
|
|
5 |
<title>jQuery UI Draggable - Constrain movement</title>
|
|
|
6 |
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
|
|
|
7 |
<script src="../../jquery-1.4.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: 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; }
|
|
|
19 |
</style>
|
|
|
20 |
<script>
|
|
|
21 |
$(function() {
|
|
|
22 |
$( "#draggable" ).draggable({ axis: "y" });
|
|
|
23 |
$( "#draggable2" ).draggable({ axis: "x" });
|
|
|
24 |
|
|
|
25 |
$( "#draggable3" ).draggable({ containment: "#containment-wrapper", scroll: false });
|
|
|
26 |
$( "#draggable4" ).draggable({ containment: "#demo-frame" });
|
|
|
27 |
$( "#draggable5" ).draggable({ containment: "parent" });
|
|
|
28 |
});
|
|
|
29 |
</script>
|
|
|
30 |
</head>
|
|
|
31 |
<body>
|
|
|
32 |
|
|
|
33 |
<div class="demo">
|
|
|
34 |
|
|
|
35 |
<h3 class="docs">Constrain movement along an axis:</h3>
|
|
|
36 |
|
|
|
37 |
<div id="draggable" class="draggable ui-widget-content">
|
|
|
38 |
<p>I can be dragged only vertically</p>
|
|
|
39 |
</div>
|
|
|
40 |
|
|
|
41 |
<div id="draggable2" class="draggable ui-widget-content">
|
|
|
42 |
<p>I can be dragged only horizontally</p>
|
|
|
43 |
</div>
|
|
|
44 |
|
|
|
45 |
<h3 class="docs">Or to within another DOM element:</h3>
|
|
|
46 |
<div id="containment-wrapper">
|
|
|
47 |
<div id="draggable3" class="draggable ui-widget-content">
|
|
|
48 |
<p>I'm contained within the box</p>
|
|
|
49 |
</div>
|
|
|
50 |
|
|
|
51 |
<div id="draggable4" class="draggable ui-widget-content">
|
|
|
52 |
<p>I'm contained within the box's parent</p>
|
|
|
53 |
</div>
|
|
|
54 |
|
|
|
55 |
<div class="draggable ui-widget-content">
|
|
|
56 |
<p id="draggable5" class="ui-widget-header">I'm contained within my parent</p>
|
|
|
57 |
</div>
|
|
|
58 |
</div>
|
|
|
59 |
|
|
|
60 |
</div><!-- End demo -->
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
<div class="demo-description">
|
|
|
65 |
<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>
|
|
|
66 |
</div><!-- End demo-description -->
|
|
|
67 |
|
|
|
68 |
</body>
|
|
|
69 |
</html>
|