2012-01-07 17 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