Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-为什么回调函数有延迟?_Jquery - Fatal编程技术网

jQuery-为什么回调函数有延迟?

jQuery-为什么回调函数有延迟?,jquery,Jquery,我希望循环并显示3个图像 当显示最后一幅图像时,再次回调runIt()函数需要很多时间 我可以将其设置为无延迟,然后再次回调函数吗 function runIt() { $("#image1,#image2,#image3").hide(); $("#image1").show(0); $("#image2").delay(1000).show(0); $("#image3").delay(2000).show(0,0,runI

我希望循环并显示3个图像

当显示最后一幅图像时,再次回调runIt()函数需要很多时间

我可以将其设置为无延迟,然后再次回调函数吗

function runIt() {      
    $("#image1,#image2,#image3").hide();
        $("#image1").show(0);
        $("#image2").delay(1000).show(0);
        $("#image3").delay(2000).show(0,0,runIt);
        }
runIt();

您的标题和问题对我来说似乎有冲突,无论如何您可以使用
setTimeout

function runIt() {      
    $("#image1,#image2,#image3").hide();
        $("#image1").show(0);
        $("#image2").delay(1000).show(0);
        $("#image3").delay(2000).show(0,0,function(){
                        setTimeout(function(){   
                          runIt();                     
                      }, 2000 );

               });
        }
runIt();

我觉得你的标题和问题有冲突,无论如何你可以使用
setTimeout

function runIt() {      
    $("#image1,#image2,#image3").hide();
        $("#image1").show(0);
        $("#image2").delay(1000).show(0);
        $("#image3").delay(2000).show(0,0,function(){
                        setTimeout(function(){   
                          runIt();                     
                      }, 2000 );

               });
        }
runIt();

是否每隔x秒运行一次该功能?然后使用setInterval()

因此,您的代码如下所示:

function runIt() {      
    $("#image1,#image2,#image3").hide();
    $("#image1").show(0);
    $("#image2").delay(1000).show(0);
    $("#image3").delay(2000).show(0);
}
setInterval(runIt, 3000);

是否要每隔x秒运行该函数?然后使用setInterval()

因此,您的代码如下所示:

function runIt() {      
    $("#image1,#image2,#image3").hide();
    $("#image1").show(0);
    $("#image2").delay(1000).show(0);
    $("#image3").delay(2000).show(0);
}
setInterval(runIt, 3000);