【发布时间】:2015-03-12 09:07:15
【问题描述】:
这里是code
<div id="button" class="overlay-down">click</div>
$(function () {
$('#button').on('click', function(){
if($(this).hasClass('overlay-down')) {
$(this).removeClass('overlay-down').addClass('overlay-up');
$('#text').stop(true, true).animate({opacity: 0}, 800, function() { // fade #text
$('#overlay').stop(true, true).slideUp(500); // then slideup #overlay
});
} else
if($(this).hasClass('overlay-up')) {
$(this).removeClass('overlay-up').addClass('overlay-down');
$('#overlay').stop(true, true).slideDown(500, function(){ // #overlay come back
$('#text').stop(true, true).animate({opacity: 1}, 800); // then #text come back
});
}
});
})
当快速点击时,动画会出错 - 叠加层向上滑动,但文本不会淡出。
每次单击按钮时,我都希望保持正在进行的动画运行以完成回调动画(不停止动画,不去结束),在进行中的动画完成之前忽略按钮单击。
我已经尝试过 is(':animated') 检测并删除 stop(true, true),它可以工作,但是还有其他简单更好的方法吗?
另外,在上面的代码中,如果我需要使用stop(),我需要将stop() 添加到每个动画元素吗?上面的代码我要加4 stop(),对吗?
谢谢你:)
【问题讨论】:
标签: jquery callback jquery-animate