0

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(){
            });
        });
    }

2 Answers 2

1

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.

0

Try passing i as a function parameter:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.