scenprogs-logo

Sequential delayed dom object iteration with Javascript (jQuery)

tutorials › javascript 25.11.16 scenprogs

When it comes to iteration through dom objects (especially with delayed steps) javascript becomes a little tricky. Imagine you want fade in objects continously but seperated through a specific timespan.

To achieve the described task I combined a recursive function with a setTimeout function. The recursive function implements the iteration functionallity and the setTimeout delays each step by a specific timespan.

If you are using mainly other programming languages the recursive function notation in javascript may look strange first. But the the function variables are declared in the function head and initialised in the function footer.

SequentialDelayedIteration function (commented)

The following code snipped includes comments to illustrate the actions inside the function. Further down you will find the same function without comments.

SequentialDelayedIteration function (compact)

how to use it