2010-06-12 182 views
0

我有鼠標懸停的問題,有時當我將鼠標移動到鏈接上時,它會循環很長一段時間,有沒有辦法只在鼠標靜止時才循環,如果鼠標不在,則停止。jquery懸停問題

 $('ul.display li').hover(function() { 

     $('ul.display li').find('#details').hide(); // hides all deatils div before showing 
     $('#light').delay('800').fadeIn("fast"); // shows div that fades out all other content. 

if($.cookie("switch_thumb") =="thumb_view" || $.cookie("switch_thumb") =="null"){//checks for cookie set for display type 
     $(this).find('#details').delay('900').animate({width:'toggle'}); // grow width 
}else{ 
     $(this).find('#details').delay('900').animate({height:'toggle'}); // grow height 
} 


     }, function() { 

      $('#light').fadeOut("fast"); // dim the light to show all content 
     $('ul.display li').find('#details').hide(); //hide all details 
    return false; // supposed to stop looping. 

     }); 
+0

您是否有示例頁面,我們可以鏈接到? '.delay()',雖然方便,但真正使事情複雜化。 – 2010-06-12 12:23:38

回答

0

退房.stop()方法

+0

這會導致更多的問題,這不是一個好主意。 – 2010-06-12 12:19:33

+0

@Nick,我的理解是,他的問題是多個盤旋的隊列......在最後的'stop(true,true)'或'clearQueue()'應該照顧那..我知道是錯誤的,雖然,之前.. – 2010-06-12 12:25:53

+0

這不是一個*顯而易見的問題,我同意。 '.delay()'使事情複雜化,['.delay()'是一個簡單的''setTimeout()''在出隊列表中](http://github.com/jquery/jquery/blob/master/src/queue.js #L75),因爲儘管你停止了* current *動畫,當這個定時器完成時,它會返回並執行下一個懸停的隊列中的任何內容,真正搞亂了那個900ms的延遲,例如它會更早執行。短版本:不要在同一個元素上混合使用'.stop()'和'.delay()'。 – 2010-06-12 12:31:08

0

我有一個類似的問題一次。 stop()也可以工作,但我所做的是在開始淡入淡出時向元素添加一個「inmotion」類,並在淡入淡出完成時將其刪除。通過在標籤打開時忽略任何懸停呼叫,它確保在下一次開始之前每個動作都必須完成。

+0

簽出[':animated' selector](http:// api.jquery.com/animated-selector/):) – 2010-06-12 12:22:54