jQuery的可拖动有拖动的问题?
问题描述:
我想恢复红块的位置,它是绿色和灰色块上的可拖动div,而不是蓝色块,它不适用于绿色块,但它在灰色块上工作,请帮助我......为此目的,我我正在使用jQuery恢复。代码和LNK下面请大家帮我 http://galtech.org/testing/drag.phpjQuery的可拖动有拖动的问题?
<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>
答
我没有使用jQuery的可拖动,但会
$("#nodrag").droppable({drop: function() { $('#draggable').css({top:'0px',left:'0px'});}});
工作?
进一步展望拖动的东西没有用有效的元素,里面块,所以我会做folllowing
$("#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')});
}});
该还原一个显而易见的方法是有可能的绿色块,因为蓝色的块是父的绿色div – shahul 2010-10-19 10:45:36