将元素拖动到特定div

时间:2010-12-13 16:51:05

标签: jquery jquery-ui jquery-ui-draggable

想要将元素拖动到特定的div,如果没有拖动到这个div会回来(恢复) 使用jQuery UI

1 个答案:

答案 0 :(得分:4)

<div id="draggable" style="width: 50px; height: 50px; border: solid 1px #000;">Drag me!</div>
<div id="droppable" style="width: 150px; height: 150px; border: solid 1px #000;">Drop here!</div>

<script type="text/javascript">
 $( "#draggable" ).draggable({ revert: true });
 $( "#droppable" ).droppable({
  accept: "#draggable",
  drop: function( event, ui ) {
   // the draggable is dropped
  }
 });
</script>