Skip to content Skip to sidebar Skip to footer

Variable Incrementer In Setinterval Function

I have lot of problems with a function and I get confused with the variable scope. I tried with a callback function, but I cannot get it. I have a function to animate a background

Solution 1:

Your variable declaration is within the function:

functionmovie(elm,jumpPx,spriteHeight,duration){
    var inc=0;
    ... other code ...
}

Therefore, each time the function is called, it resets 'inc' to 0.

var inc = 0;
functionmovie(elm,jumpPx,spriteHeight,duration){
    ... other code ...
}

If you move it outside the function, it won't keep resetting

Post a Comment for "Variable Incrementer In Setinterval Function"