在不同的时间与回调动画相同的元素
问题描述:
我现在有一些问题。我试图做这项工作,但我测试了其中一件事情没有奏效,或者没有按照预期工作。在这种情况下,回调不起作用。 我需要有三个动画,其中一个回调,在同一个元素上有不同的时间。在不同的时间与回调动画相同的元素
$('#hey').animate({
'margin-left': '100px',
}, {queue: false, duration: 1000});
$('#hey').animate({
'margin-top': '100px',
}, {queue: false, duration: 1500}, function() {
alert('hey'); // <-- this doesn't work -->
});
$('#hey').animate({
'height': '190px',
}, {queue: false, duration: 2000});
#hey {
width: 50px;
height: 50px;
background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hey"></div>
答
使用complete
财产
$('#hey').animate({
'margin-top': '100px',
}, {
queue: false,
duration: 1500,
complete: function() {
// Callback here
alert('hey'); // In your case...
}
});
也请注意,因此不以阅读文档自己
你是正确的,直到某一点的替代品。但请注意,如果所有用户阅读文档,则没有90%的问题发布在SO上。 – Miguel
谢谢。这工作 – ClaraFrazao