请-没有jQuery。
功能1使图像出现(CSS3动画)。
然后,功能2向上滑动此幻灯片底部的标题(CSS3动画)。
然后,功能3向下滑动字幕(CSS3动画)。
然后需要重复该过程。
我的问题是:如何将这些功能置于连续的循环中,并且每个功能之间都存在延迟。
HTML代码
<div id="slider">
<!-- Sildes
img_noshow means opacity:0;display:none;
img_show means opacity:1;
an_movein means a fade in effect CSS3
-->
<img id="img_1" class='img_show' src="/images/c1.jpg" style='width:960px;'/>
<img id="img_2" class='img_noshow' src="/images/c2.jpg" style='width:960px;'/>
<img id="img_3" class='img_noshow' src="/images/c3.jpg" style='width:960px;'/>
<img id="img_4" class='img_noshow' src="/images/c4.jpg" style='width:960px;'/>
<div id="slider_caption">
<p id="slider_p1" class="an_slideup"><a href="#one">This is the text going with the slide 1.</a></p>
<p id="slider_p2" class="img_noshow"><a href="#one">This is the text going with the slide 2.</a></p>
<p id="slider_p3" class="img_noshow"><a href="#one">This is the text going with the slide 3.</a></p>
<p id="slider_p4" class="img_noshow"><a href="#one">This is the text going with the slide 4.</a></p>
</div>
</div>
JAVASCRIPT代码
slide = 1;//global
function nextMove(){
slide++;
if(slide > 4){
slide = 1;
}
//img_noshow means opacity:0;display:none;
//img_show means opacity:1;
//an_movein means a fade in effect
for(i=1;i<5;i++){
document.getElementById('slider_p'+i).className = 'img_noshow';
if(i != slide){
document.getElementById('img_'+i).className = 'img_noshow';
}
else{
document.getElementById('img_'+i).className = 'an_movein';
}
}
}
function nextMove2(){
document.getElementById('slider_p'+slide).className = 'an_slideup';
}
function nextMove3(){
document.getElementById('slider_p'+slide).className = 'an_slidedown';
}
最佳答案
在每个函数的末尾使用setTimeout
方法在延迟后开始下一个:
function nextMove(){
//...all dat code
window.setTimeout(nextMove2, 500);
}
function nextMove2(){
document.getElementById('slider_p'+slide).className = 'an_slideup';
window.setTimeout(nextMove3, 500);
}
function nextMove3(){
document.getElementById('slider_p'+slide).className = 'an_slidedown';
window.setTimeout(nextMove, 500);
}
关于javascript - Javascript-循环3个函数,每个函数之间有延迟,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19523491/