2015-04-22 156 views
0

我有this代碼jQuery的懸停動畫

HTML:

<div class="random">div 1</div> 
<div class="random animation">div 2</div> 
<div class="random animation">div 3</div> 

<div class="random animated">Fade</div> 

JS:

jQuery(document).ready(function($) { 

$(".animation").hover(

    function() { 
     $(".animated").hide(500); 


    }, function() { 
     $(".animated").show(500); 


    } 
); 

}); 

DIV 2和DIV 3之間切換時,如何不觸發動畫? 我想這是簡單...


一個問題stop(),其實我使用

addClass("uk-animation-reverse uk-animation-scale-down") 

removeClass("uk-animation-reverse") 

來控制動畫= /它是這樣工作或任何其他想法?

回答

3

簡單stop如果它的每個元素的懸停事件之間運行的動畫:

jQuery(document).ready(function($) { 
    $(".animation").hover(
    function() { 
     $(".animated").stop().hide(500); 
    }, function() { 
     $(".animated").stop().show(500); 
    } 
); 
}); 

Fiddle

0

你需要停止動畫當它與相同的選擇.animated

觸發前的傳播

代碼

jQuery(document).ready(function($) { 
    $(".animation").hover(
    function() { 

     $(".animated").stop().hide(500); 

    }, function() { 

     $(".animated").stop().show(500); 

    } 
); 
}); 

JSFiddle