jQuery UI Draggable Containment

ExampleJquery ui draggable containment
Source Code Expand
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="http://www.pureexample.com/js/lib/jquery.ui.touch-punch.min.js"></script>


<!-- CSS -->
<style type="text/css">
.drag {
    width: 100px;
    height: 100px;
    border: 1px solid black;
    cursor: pointer;
    border-radius: 10px;
    text-algin: center;
    background-color: lightpink;
}
</style>


<!-- Javascript -->
<script>
$(function () {
	$("div[id='dragx']").draggable({
		containment: "#box",
		scroll: false
	});
});
</script>

<!-- HTML -->
<div id="box" style="width:500px;height:300px;border:1px solid black;background-color:lightgreen">
	<div id="dragx" class="drag"><p>Drag me</p></div>
</div>


comments powered by Disqus