Skip to content

Instantly share code, notes, and snippets.

@redknitin
Created October 5, 2015 06:00
Show Gist options
  • Save redknitin/0fb731a0e902f1440eb6 to your computer and use it in GitHub Desktop.
Save redknitin/0fb731a0e902f1440eb6 to your computer and use it in GitHub Desktop.
Droppable - Demo 1
<!doctype html><html lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<style>
</style>
<script>
$(document).ready(function() {
$('#nit1').draggable({
revert: 'invalid' //Return to orig pos if not accepted by droppable
});
$('#nit2').droppable({
//accept: '#nit1', //To filter acceptance
drop: function(event, ui){ //Does the 'snap' UI thingie
ui.draggable.position({of: $(this), my:'left top', at:'left top'});
}
});
});
</script>
</head>
<body>
<div id="nit1" style="height: 20px; width: 20px; background-color: red;">&nbsp;</div>
<div style="background-color: green; padding: 3px; display: inline-block;">
<div id="nit2" style="height: 20px; width: 20px; background-color: white;">&nbsp;</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment