setTimeout里面第一行寫alert為什么不執行?
function animate(ball,distence,cb){
setTimeout(function(){
alert(1) //為什么alert不執行?
var marginLeft = parseInt(ball.style.marginLeft,10);
if(marginLeft === distence){
cb && cb();
}else{
if(marginLeft < distence){
marginLeft++;
}else{
marginLeft--
}
ball.style.marginLeft = marginLeft+'px';
animate(ball,distence,cb);
}
},13)
}
2016-11-07
var ball1 = document.querySelector('.ball1');
var ball2 = document.querySelector('.ball2');
var ball3 = document.querySelector('.ball3');
function animate(ball,distence,cb){
setTimeout(function(){
alert(1) //為什么alert不執行?
var marginLeft = parseInt(ball.style.marginLeft,10);
if(marginLeft === distence){
cb && cb();
}else{
if(marginLeft < distence){
marginLeft++;
}else{
marginLeft--
}
ball.style.marginLeft = marginLeft+'px';
animate(ball,distence,cb);
}
},13)
}
animate(ball1,100,function(){
animate(ball2,200,function(){
animate(ball3,300,function(){
animate(ball3,150,function(){
animate(ball2,150,function(){
animate(ball1,150,function(){
//
})
})
})
})
})
})
上下我都跟老師的一樣的,不會報錯可以正常執行,但是沒有alert()
2016-11-05
settimeout ?自啟 ?不執行 ?沒理由的 ? ?要么就是報錯 停止了 ? 要不你把上下代碼都貼出來看看