假设我在一个页面上有两个动画按钮。用户点击第一个动画,它就会动画到适当的位置。我有它,所以动画打开,它停留在那里,直到用户点击页面上的其他地方。但是,当用户单击另一个动画触发按钮时,另一个动画仍在运行,一切都会搞砸,两个动画同时进行:(。那么,我如何延迟其他动画,直到动画上的关闭动画完成?Jsfiddle:http://jsfiddle.net/hBb9L/17/
$("#e").click(function (e) {
//done
$("#re").animate({
"margin-top": "104px"
}, 800);
$("#ret").animate({
"margin-top": "104px"
}, 800);
$(".popu").animate({
"margin-top": "-102px"
}, 800);
$("#s").show(200);
e.stopPropagation();哇,谢谢你读了所有这些!
发布于 2014-04-16 06:51:49
您希望使用jquery promise()。
发布于 2014-04-16 07:02:54
在animate()的属性中,确保设置了queue: true。这会将下一次单击的动画添加到动画队列的末尾,这意味着它将在当前动画完成后执行,而不是立即执行。
例如,如果我有两个按钮将测试div左右移动一点:
<button type="button" id="moveLeft">Left</button>
<button type="button" id="moveRight">Right</button>
<div id="test"></div>设置一下长方体的样式:
#test {
width: 50px;
height: 50px;
left: 0;
top: 50px;
background: #f00;
position: fixed;
}然后使用这个JavaScript来连接这些事件:
var $box = $('#test');
$('#moveRight').click(function() {
$box.animate({
queue: true,
left: "+=50"
});
});
$('#moveLeft').click(function() {
$box.animate({
queue: true,
left: "-=50"
});
});您将看到,如果您一个接一个地单击按钮,动画将排队并仅在当前按钮完成后运行。
https://stackoverflow.com/questions/23095935
复制相似问题