JavaScript SetInterval/setTimeout问题
基本上,我需要在14秒后完全重新加载/重新初始化横幅动画,但仅在13秒后-我想关闭其中一些动画,以便在再次运行之前,一切都可以停止并自行准备 我尝试了以下代码,但没有成功:JavaScript SetInterval/setTimeout问题,javascript,css,animation,dom,Javascript,Css,Animation,Dom,基本上,我需要在14秒后完全重新加载/重新初始化横幅动画,但仅在13秒后-我想关闭其中一些动画,以便在再次运行之前,一切都可以停止并自行准备 我尝试了以下代码,但没有成功: banner.init(); setInterval(function() { setTimeout(function() { banner.wheel(); // Shuts down the wheel with 1s easing banner.deinitialize();
banner.init();
setInterval(function() {
setTimeout(function() {
banner.wheel(); // Shuts down the wheel with 1s easing
banner.deinitialize(); // Sets all animations to initial stage
}, 13000);
banner.wheel(true); // Does turn the spinning wheel back on
banner.init(); // Puts all reinitialized animations back in motion
}, 14000);
我不能使用纯JS以外的任何东西。你知道怎么解决吗?在14秒间隔后,超时时间将触发13秒。您需要反转它们:
setInterval(function () {
setTimeout(function() {
banner.wheel(true); // Does turn the spinning wheel back on
banner.init(); // Puts all reinitialized animations back in motion
}, 1000);
banner.wheel(); // Shuts down the wheel with 1s easing
banner.deinitialize(); // Sets all animations to initial stage
}, 13000);
这将在13秒后触发间隔,开始缓解,然后在另一个1秒后将重新初始化其他横幅。什么意味着没有运气?发生了什么事?是否有任何错误或不当行为?如果我想在这段时间中间做点什么呢?比如说,把轮子关到一半?
// Mock banner object for testing
var banner = {
init: function(){console.log('banner.init')},
wheel: function(on){console.log('Wheel', on)},
deinitialize: function(){console.log('banner.deinitialize')},
}
banner.init();
function allOn() {
banner.wheel(true); // Does turn the spinning wheel back on
banner.init(); // Puts all reinitialized animations back in motion
}
function spinDown(){
banner.wheel(); // Shuts down the wheel with 1s easing
banner.deinitialize(); // Sets all animations to initial stage
}
function animateBanner(){
allOn()
setTimeout(spinDown, 13000);
}
setInterval(animateBanner, 14000);