繁体   English   中英

SetTimeout函数后调用函数

[英]Call a function after SetTimeout function

我有这段代码可以制作图像动画,但是我想在通过调用clearTimeout(gLoop);完成动画后调用功能AnotherAction() clearTimeout(gLoop);

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;  
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM