[jQuery] .css() in loops
[jQuery] .css() in loops
I am using a loop to initialize some elements for animation (befor
initialization they are allowed to float, but for the animation
process itself their positions need to be absolute). My code is as
follows.
$('.elemsToAnimate').each (function ()
{
var thisElem = $(this);
thisElem.css ({
top : this.offsetTop - parseInt (thisElem.css ('margin-top'), 10),
left : this.offsetLeft - parseInt (thisElem.css ('margin-left'),
10),
width : 100,
height : 100
});
});
This achieves the desired effect, namely fixing elements that were
previously allowed to float to an absolute position for animating, but
the function runs rather slow. In fact it can take over 4 seconds to
run on a list containing 120 elements.
I could really do with some help finding a speedup, if you have any
tips I'd appreciate hearign them.