I have a bunch of div's that I have set to animate at the moment. However I am wanting a way that if they've been animated (Their width would have changed from 100px to 300px for example) they won't reanimate when I click on them again. I'm new to javascript & jquery so I'm unsure how to check开发者_运维技巧 the width of a div element to place in an if statement. If I need to post the code I can if requested. Thanks
Like this:
$('selector')
.filter(function() { return $(this).width() < 300; })
.animate(...);
You should add a class to all elements you want to animate
<div class="animateMe something something">
content
</div>
and in jQuery
$('div.animateMe').animate({animate params},duration,function(){
$(this).removeClass('animateMe');
});
this will act as a flag and once animation has been done, it wont happen again on same element irrespective of height and width.
Advantage: Your code will not depend upon height/width params. if tomorrow animation changes and your blocks animate to a different height/width, this code will still be valid.
syntax for animate is jQuery.animate({animation params}, duration, callback);
Caution: Don't use the animateMe class for styling
You can use :
if($(".bunch-of-divs-class").width() == something)
{
//Do Something
}
精彩评论