jQuery UI Draggable和Droppable:当页面上的所有可拖动元素都被删除时调用一个函数

时间:2014-05-23 02:29:16

标签: javascript jquery jquery-ui

在删除所有可拖动元素后,我无法弄清楚如何调用函数。我有两个并排的专栏。右边的列表包含8个元素,这些元素被删除到左列,也有8个元素(匹配的游戏)。我可以在下面的代码中调用一个函数(alert(" drop")),当每个项目被删除时,但是如何在删除页面上的所有元素之后调用函数?谢谢!

<script type="text/javascript">
  $(function() {
    $(".draggable").draggable({
    snap: ".snapTarget",
    snapMode: "inner",
    snapTolerance: 15,
    revert: "invalid"
    });

    $(".word1 .wordBg").draggable({
    snapTolerance: 15,
    revert: "invalid"
    });
    $(".word1").droppable({
    accept: ".word1",
    drop: function(){
    alert("drop");
   }
   });
  .... word2 . . .
  .... word8 
  });
  </script>

1 个答案:

答案 0 :(得分:0)

感谢上面评论中的gp和silver,这是工作代码:

<script type="text/javascript">
$(".kaminari_match_pagination").hide()
var dropCount = 0;
var wordCount = $('.word').length / 2;

$(function() {
$(".draggable").draggable({
  snap: ".snapTarget",
  snapMode: "inner",
  snapTolerance: 15,
  revert: "invalid"
  });

$(".word1 .wordBg").draggable({
  snapTolerance: 15,
  revert: "invalid"
  });
$(".word1").droppable({
  accept: ".word1",
  drop: function(){
  dropCount++;
    if (dropCount === wordCount) {
      $(".kaminari_match_pagination").show();
 }
 });
 .... word2 . . .
 .... word8 
});
</script>