i have some code similar to this, that moves inside some images... it works but it doesn't seem to respect timer
var i = 1;
var indexArray = array(1,2,3);
var timerx = new Array();
$( indexArray ).each(function( indexArraykey ) {
function internalCallback ( i, indexArraykey ) {
val = indexArray[indexArraykey];
console.log("test " + i + val);
});
timerx[i] = setTimeout( internalCallback( i, indexArraykey ), i * 500000 );
i++;
});
A few points :
i
has the value of end of loop by the time the callback is called.$.each(array,
, not $(array).each(
So it seems that what you want is in fact this :
var indexArray = array(1,2,3);
var timerx = [];
$.each(indexArray, function( indexArrayValue, i ) {
timerx.push(setTimeout(function(){
console.log("test " + i + ' : ' + indexArrayValue);
}, (i+1) * 500000));
});