That would be the approach I would take if I could, but unfortunately
every element has to have it's own top left coordinates, and those
coordinates are different for every element. Otherwise they would all
just collapse into the top left hand corner of their containing
element. They start off as li elements with a display: block and
float: left style applied to produce a table-like view with liquid
layout. When they are being moved around they all need to be
position: absolute, but this causes them all to move to position 0,0
unless they each get an explicit top and left attribute added.
On Jun 19, 6:10 pm, Renato Formato <[EMAIL PROTECTED]> wrote:
> Gordon ha scritto:
>
> > 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.
>
> I think the best approach is to add a class to the elements and leave to
> the stylesheet the position setting if possible.
>
> At least you could avoid the
> - parseInt (thisElem.css ('margin-top'), 10)
> and
> - parseInt (thisElem.css ('margin-left')
>
> setting a new rule that nullify the margins.
>
> If you are lucky, but it depends upon your layout, you could avoid to
> call this.offsetTop and this.offsetLeft. In this case you could avoid
> the each function too, calling a simple $('.elemsToAnimate').css() on
> your elements.
>
> Renato