| 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 - Constrain movement</title> |
| 7 |
<link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 |
<link rel="stylesheet" href="../demos.css"> |
| 9 |
<style> |
| 10 |
.draggable { width: 90px; height: 90px; padding: 0.5em; float: left; margin: 0 10px 10px 0; } |
| 11 |
#draggable, #draggable2 { margin-bottom:20px; } |
| 12 |
#draggable { cursor: n-resize; } |
| 13 |
#draggable2 { cursor: e-resize; } |
| 14 |
#containment-wrapper { width: 95%; height:150px; border:2px solid #ccc; padding: 10px; } |
| 15 |
h3 { clear: left; } |
| 16 |
</style> |
| 17 |
<script src="../../external/requirejs/require.js"></script> |
| 18 |
<script src="../bootstrap.js"> |
| 19 |
$( "#draggable" ).draggable({ axis: "y" }); |
| 20 |
$( "#draggable2" ).draggable({ axis: "x" }); |
| 21 |
|
| 22 |
$( "#draggable3" ).draggable({ containment: "#containment-wrapper", scroll: false }); |
| 23 |
$( "#draggable4" ).draggable({ containment: "parent" }); |
| 24 |
</script> |
| 25 |
</head> |
| 26 |
<body> |
| 27 |
|
| 28 |
<h3>Constrain movement along an axis:</h3> |
| 29 |
|
| 30 |
<div id="draggable" class="draggable ui-widget-content"> |
| 31 |
<p>I can be dragged only vertically</p> |
| 32 |
</div> |
| 33 |
|
| 34 |
<div id="draggable2" class="draggable ui-widget-content"> |
| 35 |
<p>I can be dragged only horizontally</p> |
| 36 |
</div> |
| 37 |
|
| 38 |
<h3>Or to within another DOM element:</h3> |
| 39 |
<div id="containment-wrapper"> |
| 40 |
<div id="draggable3" class="draggable ui-widget-content"> |
| 41 |
<p>I'm contained within the box</p> |
| 42 |
</div> |
| 43 |
|
| 44 |
<div class="draggable ui-widget-content"> |
| 45 |
<p id="draggable4" class="ui-widget-header">I'm contained within my parent</p> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
|
| 49 |
<div class="demo-description"> |
| 50 |
<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> |
| 51 |
</div> |
| 52 |
</body> |
| 53 |
</html> |