我有制作图像动画的代码,但我想在动画完成时通过调用 clearTimeout(gLoop);
调用函数 AnotherAction()
var Animate = function(){
Clear();
MoveDown();
gLoop = setTimeout(Animate,40);
}
var MoveDown = function(){
// animation code
if(velocity==0){
clearTimeout(gLoop);
AnotherAction(); //Here is not working
}
}
我应该在哪里调用 AnotherAction()
?
最佳答案
我认为问题在于您在下次设置超时之前清除超时。 MoveDown
正在清除超时,但是一旦控制权切换回 Animate,您就会再次设置它。
尝试这样的事情:
var Animate = function(){
Clear();
if (MoveDown())
gLoop = setTimeout(Animate,40);
}
var MoveDown = function(){
// animation code
if(velocity==0){
AnotherAction(); //Here is not working
return false;
}
return true;
}
关于javascript - 在 SetTimeout 函数之后调用一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8557526/