jQuery animation detect if animating?
Is their a way to detect 开发者_运维知识库if an element is animating or detect if values of an element is changing?
Because I need to trigger a function if an element is animating. Not onComplete of animate.
The following returns true when the selected element is animating:
var isAnimating = $("#someid").is(':animated');
More detail:
http://api.jquery.com/animated-selector/
and/or
http://api.jquery.com/animate/
step: A function to be called after each step of the animation.
A simple way would be adding a global boolean that gets set to true
as soon as the animation starts. Then you add a callback function to the animation that sets it to false
as it finishes.
var running = false;
$('#start').click(function(){
running = true;
$('#target').animate({opacity: 0.5},'slow',function(){
running = false;
});
});
Edit: Oh I guess there's a selector for it.
精彩评论