我想要恢复红色块的位置,这是绿色和灰色块上的可拖动div而不是蓝色块,它不能在绿色块上工作但是它在灰色块上工作请帮助我...为此目的我正在使用jquery还原。代码和lnk在下面请帮助我 http://galtech.org/testing/drag.php
<style type="text/css">
#draggable { width: 100px; height: 70px; background: red; }
#nodrag { width: 200px; height: 270px; background: #00CC66; }
</style>
</head>
<body >
<div style="background:#CCCCCC;">
<div id="droppble_blue" style="background:#99CCCC; height:500px; width:620px;">
<div id="draggable" >Drag</div>
<div id="nodrag" class="new">no Drag & drop here</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function() {
$("#draggable").draggable({ revert: "invalid" });
$("#droppble_blue").droppable({drop: function() { alert('dropped');}});
});
</script>
答案 0 :(得分:0)
我没有使用可拖动的jquery但是
$("#nodrag").droppable({drop: function() { $('#draggable').css({top:'0px',left:'0px'});}});
工作?
进一步研究可拖动的东西没有明显的方法来恢复有效元素内的块,所以我会做以下
$("#draggable").draggable('option', 'start', function(){
//when drag starts save the positions somewhere
$(this).data('left',$(this).css('left')).data('top',$(this).css('top'))
});
$("#nodrag").droppable({drop: function(e,ui) {
//when dropped on an invalid block move it back to where it was (you could change this to animate to mimic revert)
$(ui.draggable)
.css({left:$(ui.draggable).data('left'),top:$(ui.draggable).data('top')});
}});