我正在尝试循环我的函数,但是当我将它与 setInterval 一起使用时,它会继续循环 i3-CTA 而不是整个函数。
window.onload = function start() {
loop();
}
function loop(){
setInterval(function(){
$("#i3-content").delay(6500).fadeOut(function(){
if ($('#i3-content').is(':hidden')) {
$('#i3-CTA').fadeIn();
$("#i3-CTA").delay(6000).fadeOut(function(){
if ($('#i3-CTA').is(':hidden')) {
$("#i3-content").fadeIn();
}
});
}
});
});
}
我对此还很陌生,但希望有人能提供帮助,谢谢。
最佳答案
window.onload = function start() {
setInterval(loop(), 6500)
}
function loop(){
debugger;
$("#i3-content").fadeOut(function(){
if ($('#i3-content').is(':hidden')) {
$('#i3-CTA').fadeIn();
$("#i3-CTA").delay(6000).fadeToggle(function(){
if ($('#i3-CTA').is(':hidden')) {
$("#i3-content").fadeToggle();
}
});
}
});
}
#i3-content{
height:20px;
background:red;
}
#i3-CTA{
height:20px;
background:green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='i3-content'></div>
<div id='i3-CTA'></div>
关于javascript/jquery 循环函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33515165/