Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.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
Javascript 是否以连续方式执行循环中的所有元素?_Javascript_Jquery_Css - Fatal编程技术网

Javascript 是否以连续方式执行循环中的所有元素?

Javascript 是否以连续方式执行循环中的所有元素?,javascript,jquery,css,Javascript,Jquery,Css,如何在循环中执行函数,使循环中的下一个元素仅在前一个元素完成时执行 $(".welcome>p").each(function() { var $this = $(this); setTimeout(function() { $this.animate({ opacity: 1 }, 600); }); }); 因此,此代码中的所有p元素将同时运行。如何更改它,使p元素按顺序逐个显示 谢谢, YonL每个的

如何在循环中执行函数,使循环中的下一个元素仅在前一个元素完成时执行

$(".welcome>p").each(function() {
    var $this = $(this);
    setTimeout(function() {
        $this.animate({
            opacity: 1
        }, 600);
    });

});
因此,此代码中的所有p元素将同时运行。如何更改它,使p元素按顺序逐个显示

谢谢,
YonL

每个
的第一个参数是
索引,因此您可以使用该索引来增加
设置超时
,如下所示:

$(".welcome>p").each(function( idx ) {
    var $this = $(this);
    setTimeout(function() {
        $this.animate({
            opacity: 1
        }, 600);
    }, idx * 600);

});

每个
的第一个参数是
索引
,因此可以使用该索引来增加
设置超时
,如下所示:

$(".welcome>p").each(function( idx ) {
    var $this = $(this);
    setTimeout(function() {
        $this.animate({
            opacity: 1
        }, 600);
    }, idx * 600);

});

每个
的第一个参数是
索引
,因此可以使用该索引来增加
设置超时
,如下所示:

$(".welcome>p").each(function( idx ) {
    var $this = $(this);
    setTimeout(function() {
        $this.animate({
            opacity: 1
        }, 600);
    }, idx * 600);

});

每个
的第一个参数是
索引
,因此可以使用该索引来增加
设置超时
,如下所示:

$(".welcome>p").each(function( idx ) {
    var $this = $(this);
    setTimeout(function() {
        $this.animate({
            opacity: 1
        }, 600);
    }, idx * 600);

});