jQuery UI Draggable Events

ExampleJquery ui draggable events
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;
    padding: 5px;
    margin-left: 5px;
    text-algin: center;
    background-color: lightgreen;
}

.info {
    width: 200px;
    height: 20px;
    border: 1px solid black;
    text-align: center;
    margin-bottom: 2px;
    background-color: orange;
}
</style>


<!-- Javascript -->
<script>
var count = 0;
$(function () {
	$("#drag").draggable({
		containment: "#box",
		start: function () {
			$("#drag p").html("<p>Drag me around</p>Drag started!");
		},
		drag: function () {
			count++;
			$("#info").html("Drag event fired " + count + " times");
		},
		stop: function () {
			$("#drag p").html("<p>Drag me around</p>Drag stopped!");
		}
	});
});
</script>

<!-- HTML -->
<div id="box" style="width:600px;height:200px;border:0px solid black;margin-bottom:5px">
    <div id="drag" class="drag">
        <p>Drag me around</p>
    </div>
</div>
<div id="info" class="info">Drag event fired 0 times</div>


comments powered by Disqus