【发布时间】:2016-08-05 11:18:41
【问题描述】:
在下面的代码中,我尝试循环三个函数,这些函数仅在前一个函数完成后才触发,最后一个函数调用第一个函数以重新开始该过程。使用 setInterval/setTimout 不会是很好的答案,因为 RequestAnimationFrame 取代了它们作为一种更清洁的做事方式,但我不知道如何将 RequestAnimationFrame 应用于此代码。同样使用这两种方法也无法回答为什么第三个函数不调用第一个函数的问题。
<body onload="runOne()">
function runOne(){
var x = document.getElementById("rightBox");
document.getElementById("rightBox").style.animation = "scrollTextTwo 10s";
x.addEventListener("animationend",runTwo);
};
function runTwo(){
var x = document.getElementById("rightBoxTwo");
document.getElementById("rightBoxTwo").style.animation = "scrollTextTwo 10s";
x.addEventListener("animationend",runThree);
};
function runThree(){
var x = document.getElementById("rightBoxThree");
document.getElementById("rightBoxThree").style.animation =
"scrollTextTwo 10s";
x.addEventListener("animationend",runOne);
};
上面的代码只运行一次,它将播放/动画所有三个函数,但在“runThree()”完成后停止。我想知道“runThree()”如何在运行第三个动画完成后调用“runOne()”?
【问题讨论】:
标签: javascript html css