2010-08-12 159 views
2

我想知道我該如何解決這個可怕的簡單問題。jquery動畫問題

我已經安裝了顏色插件以平滑改變背景顏色。所以當Im在短時間內在它上面徘徊幾次時,它會重複並重復動畫,就像它的一個堆棧。 我該如何解決這個問題?任何想法?

$("#page-bar > ul > li").mouseenter(function(){ 
     $(this).animate({ 
        backgroundColor: "#3c78a7" 
       }),500; 
      }).mouseleave(function(){ 
       $(this).animate({ 
        backgroundColor: "#333333" 
       }),500; 
      }); 
+0

代碼看起來不錯其實 – Mauro 2010-08-12 15:01:21

回答

0
$("#page-bar > ul > li").mouseenter(function(){ 
     $(this).stop().animate({ 
        backgroundColor: "#3c78a7" 
       }),500; 
      }).mouseleave(function(){ 
       $(this).stop().animate({ 
        backgroundColor: "#333333" 
       }),500; 
      }); 
2

使用停止()停元件的電流動畫。 http://api.jquery.com/stop/

+0

確定,但在鼠標離開或我在哪裏都到位了嗎? – lain 2010-08-12 14:57:54

+0

感謝我的作品<3 – lain 2010-08-12 14:59:56