繁体   English   中英

jQuery Draggable有拖动问题?

[英]jquery draggable has an issue on dragging?

我想恢复红色块的位置,红色块是绿色和灰色块上可拖动的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>

我没有使用可拖动的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')});
}});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM