I am using jQuerys animate function on a plugin, on many elements simulatensly with different durations for each element. I want to know if any animation is running or if there is no animation at all. So i came up with this:
if( $div1.is(':animated') || $div2.is(':animated') || $div3.is(':animated') ) return true;
else return false;
or this:
if( $div1.add($div2).add($div3).is(':animated') ) return true;
else return false;
Which is better???
Do you know any other method???
I dont want this code $("*").is(':animated');
because it will check all animations and from other plugins animations.
Have in mind that I have many elements, not just 3.
Thanks for reading...
I would go with the second as it is less code to read and think about it.
Generally, DRY is better.
You could also refactor that...
return $div1.add($div2).add($div3).is(':animated');
Perhaps you could put a class on the divs you would like to check for animation?
if ($(".myclass").is(":animated")) return true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With