2011-06-15 130 views
1

我有一個div是display:none,當鼠標移過另一個div時我想淡入它,當鼠標離開div時淡出它。問題是,一旦我越過了div,無論鼠標是否保持開啓或關閉,它都保持淡入淡出10次左右。有人有主意嗎?鼠標懸停鼠標一直執行

$(document).ready(function() { 

     $(".pic").mouseout(function(){ 
$(this).children('#summary').fadeOut(2000); 
    }).mouseover(function(){ 
    $(this).children('#summary').fadeIn(2000); 
    }); 

}); 

回答

4

在調用每個處理程序中的動畫之前調用.stop()。

$(function(){ 
    $('.pic').hover(function(){ 
    $(this).children('#summary') 
     .stop(true) 
     .fadeOut(2000); 
    }), 
    function(){ 
    $(this).children('#summary') 
     .stop(true) 
     .fadeIn(2000); 
    }); 
}) 

編輯:哎呀,不得不解決我的複製/粘貼

+0

我已經嘗試過,然後什麼也沒有發生。 $(本)。兒童( '#最新註釋')停止()淡入(2000年)。 – Scarface 2011-06-15 17:55:57

+1

你傳遞給stop()的參數是什麼?如果您調用stop(true),它將清除動畫隊列 - 如果您調用stop(true,true),它將清除隊列並完成動畫。 – kinakuta 2011-06-15 18:01:29

+0

謝謝kinakuta,它現在正在工作。 – Scarface 2011-06-15 18:10:25

0

使用插件像hoverIntent扼殺/出消息的速率。通常有幫助。