Reputation: 539
My script is as follows which should replay mouse image inside a div but settimeout is not working and there is no error in console also:
function play(data, value) {
var data = data;
function run() {
var nowTime;
var newdata = data.splice(0, 1); // after splice, data will be auto updated
if (newdata.length == 1) {
nowTime = newdata[0][6];
var timer = setTimeout(function() {
if (newdata[0][3] == '14') {
replay(newdata[0][0], newdata[0][1]);
}
preTime = nowTime;
// continue run next replay
run();
}, nowTime - preTime);
}
}
run();
}
Please help me. How to solve this issue.
thanks in advance
Upvotes: 0
Views: 337
Reputation: 322
try this
var newdata;
var nowTime;
var preTime;
function play(data, value)
{
newdata= data.splice( 0, 1 ); // after splice, data will be auto updated
if ( newdata.length == 1 ) {
nowTime = newdata[0][6];
var timer = setTimeout("timer();",nowTime - preTime );
}
}
function timer()
{
if(newdata[0][3] == '14'){
replay( newdata[0][0], newdata[0][1]);
}
preTime = nowTime;
play();
}
play();
Upvotes: 1