user5606687
user5606687

Reputation:

Repeating function while incrementing [i] within

I'm trying to call repeatThis n times while incrementing myArr[i] on each iteration. Putting a loop inside the function before the last bracket will blow up the browser call stack. Also can't put a function within a loop without getting errors.

Functionally, I want it to flip through jpegs so it looks like a movie.

 function repeatThis () {
        $(myArr[i]).fadeIn(100, function(){
            $(myArr[i]).fadeOut(100, function(){
            });
        });
    }

Upvotes: 0

Views: 38

Answers (2)

Jerome Hudak
Jerome Hudak

Reputation: 116

Use each!! So the syntax looks like

$.each(myArr, function( index, value ) {
  $(myArr[index]).fadeIn(100, function(){
    $(myArr[index]).fadeOut(100, function(){
  });
});

This should work, unless there is something else in your code messing up your array.

Upvotes: 1

Adam
Adam

Reputation: 550

Try passing i as a function parameter:

function repeatThis(i) {
    ...
})(i);

Upvotes: 0

Related Questions