-1

我创建了一个 jQuery 函数,它一个接一个地重复地从顶部 50px 到顶部 150px 为元素设置动画。

我正在尝试在每个单独元素的动画之间创建一个暂停(不是迭代之间的暂停)。在第一次迭代中,什么都没有发生。在下面的例子中,该函数考虑了 delay(),但只考虑了部分元素。

您可以在下面的链接中看到整个操作。

整个代码

    $(".but").click(function() {
        function repeat() {
            var count = $(".box").length;
            $($(".box").get().reverse()).each(function(i) {
                $(this).delay(600 * i).animate({
                    top: "150px",
                    duration: 600,
                    easing: "linear",
                    complete: function() {
                        $(".box").each(function(i) {
                            $(this).delay(500);
                        });
                        if (count == 0) {
                            $(".box").css("top", "50px");
                            repeat();
                        };
                    }
                });
            });
        };
        repeat();
    });
4

1 回答 1

1

你有这个complete:

$(".box").each(function(i){
    $(this).delay(500);
});

我把它移到了之前$(this).delay(600 * i).animate [...]

现在这些块之间有延迟。

这是你想要的吗?http://jsfiddle.net/HdpPj/12/

于 2013-05-17T12:21:57.880 回答