2012-01-07 63 views
0

我有一个问题,我有这样的代码:如何使事件等待,直到jQuery的翻页效果结束?

$(document).ready(function(){ 
    /* The following code is executed once the DOM is loaded */ 

    $('.clsks').mouseenter(function() { 

     var ob = $(this); 
     var dar = $(this).attr('ids'); 
     var obj1 = $('#sponsorFlip'+dar); 
     var obj2 = $('#sponsorData'+dar); 

     obj1.flip({ 
       direction:'lr', 
       speed: 350, 
       onBefore: function(){ 
        // Insert the contents of the .sponsorData div (hidden from view with display:none) 
        // into the clicked .sponsorFlip div before the flipping animation starts: 
        obj1.html(obj2.html()); 

       } 
      }); 

      // Setting the flag: 
     //obj1.data('flipped',true); 

     }).mouseleave(function() { var dar = $(this).attr('ids'); 
     var obj1 = $('#sponsorFlip'+dar); obj1.revertFlip(); }); 

}); 

我需要做的事件MouseEnter等到这个jQuery的翻转完成的Cuz有时候如果有人的mouseenter快速的鼠标离开失败的Cuz“obj1.html(obj2.html( ));”超过它。

但我只需要做出MouseEnter事件等待jQuery的翻转完成。

+0

您无法在mouseenter上启动翻转,但需要等待翻转完成。这没有任何意义。当你得到mouseenter事件时,它已经发生了。翻转完成后你想做什么操作?或者,你试图解决的真正问题是什么。 – jfriend00 2012-01-07 03:29:15

回答

0

请参阅文档翻页方法:http://lab.smashup.it/flip并添加onEnd:函数。下面是该文档中的一个示例:

$("#flipbox").flip({ 
    direction:'tb', 
    onBefore: function(){ 
      console.log('before starting the animation'); 
    }, 
    onAnimation: function(){ 
      console.log('in the middle of the animation'); 
    }, 
    onEnd: function(){ 
      console.log('when the animation has already ended'); 
    } 
}) 
+0

是有没有办法来检查,如果鼠标仍然在一个元素?如果是的话,我可以使用onEnd回调 – 2012-01-07 03:19:12

+0

您可以从mouseenter事件获取当前的鼠标位置,并通过获取该对象的位置/大小和比较来查看它是否在特定对象上。我不确定你真的想要解决什么问题,所以不知道如何更具体地提供帮助。也许如果你描述真正的问题,我们可以提供更好的建议。 – jfriend00 2012-01-07 03:32:54

+0

你可以在'mouseenter'开始设置一个标志,表明该鼠标在和'mouseleave'关闭标志。在动画的'onEnd()',您可以检查是否鼠标仍然在通过检查该标志的值。 – techfoobar 2012-01-07 04:38:27