You could also pile up actions then run them (untested):

var stack = {
        delay: 1000,
        actions:[],
        run: function() {
                if (stack.actions.length) {
                        stack.actions.shift()();
                        setTimeout(stack.run, stack.delay);
                }
        }
};

$(elems).each(function(){
        var that = this;
        stack.actions.push(function(){
                $(that).dostuff();
        });
});

stack.run();

Franck.

Karl Rudd a écrit :
> For _most_ browsers changes in the CSS are not reflected in the layout
> until _after_ your JavaScript is finished executing. I believe the
> exception is Opera (or is it Safari...?), which also updates the
> layout after a certain amount of time.
>
> If you want to display the changes progressively you'll need to use a
> setTimeout() called function. Something like:
>
> function dostuff( elem ) {
>   elem.dostuff();
> }
>
> $(elems).each(function(){
>   var elem = this;
>   setTimeout( function(){ dostuff( elem ); }, 0 )
> });
>
> Due to the fact that JavaScript is single threaded, the functions
> called using setTimeout will be called one after the other. There is a
> "break" after each call which should allow the browser to update the
> layout of the page.
>
> If the 0 delay in the setTimeout doesn't work then change something like 20.
>
> Karl Rudd
>
> On 9/4/07, boermans <[EMAIL PROTECTED]> wrote:
> >
> > I'm looking for a tidy way to call a function to iterate over a group
> > of DOM elements, with a small delay after the function completes
> > before it is called again with the following element.
> >
> > Pseudo code:
> > ==========
> > $(elems).each(function(){
> >     $(this).dostuff();
> >     // wait a moment
> >     // continue
> > });
> >
> > I am aware of the pause plugin (linked on the old plugin page) but I'm
> > confused by it's reference to type. My function does not use any fx or
> > animations - what other 'types' are there in jQuery?
> >
> > Why you ask?
> > ==========
> > My attempted script manipulates a bunch of css attributes based on
> > dimensions and positions of elements in the DOM. I believe I need the
> > delay to give the browser an opportunity to update between each call -
> > ensuring the DOM is updated the script's css changes before
> > proceeding.
> >
> > Perhaps I could use .animate() and it's callback function to iterate?
> > My attempts at this are a mess! Any help is welcome.
> >
> > Cheers
> > Ollie
> >
> >

Reply via email to