<script src="jquery.js"></script>
<script src="ui.core.js"></script>
<script src="ui.draggable.js"></script>
<script src="ui.droppable.js"></script>
<style type="text/css">
body{
font:normal 12px Verdana;
margin:0;
padding:0;
}
.wrap{
width:600px;
position:relative;
padding:10px;
}
.sourcearea{
width:150px;
float:left;
}
.items {
z-index: 100;
}
.droparea {
float:right;
background-color: #EFEFE0;
border: 1px solid #EFEFE0;
width: 100px;
min-height: 100px;
border:1px solid;
}
.droparea img{
margin:5px;
}
.dropareahover {
background-color:#EFD2A4;
border-color:#DFA853;
}
.summary{
padding:10px;
}
.summary span{
font-weight:bold;
}
</style>
</head>
<body>
<div class="wrap">
<div class="sourcearea">
<span class="draggable" id="itemsheep"><img src="sheep.jpg" width="100"></span>
<span class="draggable" id="itemdog"><img src="dog.jpg" width="100"></span>
</div>
<div class="droparea" id="dropsheep">SHEEP DROP</div>
<div class="droparea" id="dropdog">DOG DROP</div>
</div>
<script>
$(document).ready(function() {
$("#itemsheep").draggable({
snap: '#dropsheep',
revert: true
});
$("#itemdog").draggable({
snap: '#dropdog',
revert: true
});
$("#dropsheep").droppable({
accept: "#itemsheep",
drop: function(ev, ui) {
//... logic to accept the drop ...
var dropOk = true; //harcoded for simplicity
if (dropOk){
alert("sheep dropped success");
//drop img in and snap without reverting
}else{
alert("dropped failed");
//revert effect will be executed (as planned)
}
}
});
$("#dropdog").droppable({
accept: "#itemdog",
drop: function(ev, ui) {
//... logic to accept the drop ...
var dropOk = true; //harcoded for simplicity
if (dropOk){
alert("dog dropped success");
//drop img in and snap without reverting
}else{
alert("dropped failed");
//revert effect will be executed (as planned)
}
}
});
});
</script>
</body>
</html>