Skip to content

Instantly share code, notes, and snippets.

@matherton
Created September 18, 2013 09:07
Show Gist options
  • Save matherton/6606557 to your computer and use it in GitHub Desktop.
Save matherton/6606557 to your computer and use it in GitHub Desktop.
Draggable jQuery Div with callback functions (comments included)
<html>
<head>
<title>Dragable Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="ui.js"></script>
<style>
.item {
height: 180px;
width: 180px;
border: 3px solid grey;
background-color: #ffffff;
}
.movablecontainer {
height:800px;
width: 800px;
background-color: #000000;
}
</style>
</head>
<body>
<div class="movablecontainer">
<div class="item" id="movable">
<p>This div is moveable</p>
</div>
<div id="event" style="color:white;"></div>
</div>
</body>
</html>
$(document).ready(function(){
$("#movable").draggable({ containment: 'parent', cursor: 'pointer', opacity: 0.60, grid: [220, 220], revert: true,
/* call back functions allow events to occur the parent function is in opereation */
start: function () {
$('#event').text('dragging started');
},
drag: function () {
$('#event').text('dragging');
},
stop: function () {
$('#event').text('draggin finished');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment