2012-06-22 119 views
0

我有這樣的代碼:如何延遲mouseout功能?

var shortcuts = $('#geo_shortcuts'); 
    shortcuts.find('li').hoverIntent(
     function() { 
      // Open the Panel 
      $(this).find('.geo_shortcuts_content').stop().animate({ 
       top: '-122' 
      }, 300); 
     }, 
     function() { 
      //Close de Panel 
      $(this).find('.geo_shortcuts_content').stop().animate({ 
       top: '0' 
      }, 400); 
     } 
    ); 

我該怎麼辦,只允許2秒鼠標移出後關閉面板?我知道我應該做一個settimeout函數,但我不知道如何。

回答

0

您可以使用一個定時器來做到這一點

hideDelayTimer = null; 
    shortcuts.find('li').hoverIntent(
     function() { 
      // Open the Panel 
      clearTimeout(hideDelayTimer); 
      $(this).find('.geo_shortcuts_content').stop().animate({ 
       top: '-122' 
      }, 300); 
     }, 
    function() { 
     //Close de Panel 
     clearTimeout(hideDelayTimer); 
     hideDelayTimer = setTimeout(function() { 
      hideDelayTimer = null; 
       $(this).find('.geo_shortcuts_content').stop().animate({ 
        top: '0' 
       }, 400); 
     }, 2000); 

有一個愉快的一天

+0

thak你Boulilou,這解決了我的問題 – user1384644

+0

永遠幸福幫助。你能用綠色勾號來關閉這個話題嗎? – sdespont

1

嘗試使用delay()方法:

$(this).find('.geo_shortcuts_content').stop().delay(2000).animate({ 
    top: '0' 
}, 400);