Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.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 如何使多个jQuery animate()调用一个接一个地工作?_Javascript_Jquery_Animation_Jquery Animate - Fatal编程技术网

Javascript 如何使多个jQuery animate()调用一个接一个地工作?

Javascript 如何使多个jQuery animate()调用一个接一个地工作?,javascript,jquery,animation,jquery-animate,Javascript,Jquery,Animation,Jquery Animate,当我单击“aa”块时,“aa”和“bb”同时动画。javascript是否将animate()函数以非阻塞方式发布到单独的线程中?或者这个函数被多次输入,数千次回调使用阻塞型函数调用?我如何在需要时使animate()逐个处理项目(也许使用计时器可以,但我必须始终使用计时器吗?) 从jQuery文档中: 完成 类型:函数() 动画完成后要调用的函数 因此: 从jQuery文档中: 完成 类型:函数() 动画完成后要调用的函数 因此: 工作正常,但最近我建议使用选项版本可能会更干净: .anima

当我单击“aa”块时,“aa”和“bb”同时动画。javascript是否将animate()函数以非阻塞方式发布到单独的线程中?或者这个函数被多次输入,数千次回调使用阻塞型函数调用?我如何在需要时使animate()逐个处理项目(也许使用计时器可以,但我必须始终使用计时器吗?)


从jQuery文档中:

完成
类型:函数()
动画完成后要调用的函数

因此:


从jQuery文档中:

完成
类型:函数()
动画完成后要调用的函数

因此:

工作正常,但最近我建议使用选项版本可能会更干净:

.animate(属性、选项)

因此:

javascript
函数位(i,j){
$(i).动画({高度:“500px”}{
持续时间:400,
完成:函数(){
$(j).制作动画({宽度:“500px”});
}
});
};

done
可替换为(旧选项)
complete
,或
总是
总是
done
失败
是现在流行的承诺事件)

编辑:为了澄清,我建议这样做的原因有三个:

1) 您不需要提供对您来说无关紧要的属性(在本例中为easing)

2) 如果您认为其他属性很重要,那么添加这些属性通常是微不足道的

3) (最重要的是)当您稍后编辑代码时,您将完全理解嵌套函数的用途,而无需考虑它

有效,但最近我建议使用选项版本可能会更干净:

.animate(属性、选项)

因此:

javascript
函数位(i,j){
$(i).动画({高度:“500px”}{
持续时间:400,
完成:函数(){
$(j).制作动画({宽度:“500px”});
}
});
};

done
可替换为(旧选项)
complete
,或
总是
总是
done
失败
是现在流行的承诺事件)

编辑:为了澄清,我建议这样做的原因有三个:

1) 您不需要提供对您来说无关紧要的属性(在本例中为easing)

2) 如果您认为其他属性很重要,那么添加这些属性通常是微不足道的


3) (最重要的是)当您稍后编辑代码时,您将完全理解嵌套函数的用途,而无需考虑它

取决于javascript引擎…javascript没有内置的
animate
功能。您可以看到它是jQuery对象的一个方法。检查jQuery源代码。好的,我会查看源代码。您有一个额外的
做“;”平均并行执行?取决于javascript引擎…javascript没有内置的
animate
功能。您可以看到它是jQuery对象的一个方法。检查jQuery源代码。好的,我会查看源代码。您有一个额外的
做“;”意思是并行执行?
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
    <script>

        function growbits(i,j) {
            $(i).animate({ height: "500px" }); // looks working concurrently
            $(j).animate({ width: "500px"});   // with this one
        };

    </script>
</head>
<body>
    <p id="bb" style="background: #f00; height: 50px; width: 255px; margin: 10px;">asdasd</p>  
    <p id="aa" onclick="growbits(aa,bb);" style="background: #f00; height: 50px; width: 255px; margin: 10px;">
        gfhjjjgfhgkjfhkjtkjyhtkjyhkhfukhgkudfgk

    </p>
</body>
</html>
self.element.animate(
            $.extend(style, top && left ? { top: top, left: left } : {}), {
                duration: o.animateDuration,
                easing: o.animateEasing,
                step: function() {

                    var data = {
                        width: parseInt(self.element.css('width'), 10),
                        height: parseInt(self.element.css('height'), 10),
                        top: parseInt(self.element.css('top'), 10),
                        left: parseInt(self.element.css('left'), 10)
                    };

                    if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });

                    // propagating resize, and updating values for each animation step
                    self._updateCache(data);
                    self._propagate("resize", event);

                }
            }
        );
.animate( properties [, duration ] [, easing ] [, complete ] )
function growbits(i,j) {
    $(i).animate({ height: "500px" }, {}, 400, function () {
        $(j).animate({ width: "500px"});
    });

};