我已经阅读了很多主题和jQuery文档,但我仍然无法解决这个问题 .
我所拥有的是具有不透明度0和一些背景颜色的div . 在某个按钮的用户“点击”事件中,我调用“StartAnimationFuncton”函数,使div具有不透明度1并添加加载图像 .
然后,当从服务器收到信息时,我调用“StopAnimationFuncton”函数,该函数应该删除加载div,然后再次使用不透明度为0的背景div .
注意:我在删除之前将延迟(1000)设置为加载,因为如果请求执行得太快,则加载显示一毫秒并且看起来很难看 .
//StartAnimationFuncton
$("#BackGroundDiv").stop('fx',true,false).animate({opacity:1.0},1000,function(){
$('#ShopperPortalLoadingDivContentTable').remove();
$('<div id="Loading" style="width:100%;height:100%"></div>').hide().appendTo('#BackGroundDiv').stop('fx',true,false).fadeIn(500,function(){
...
//Waiting data from the server - when the date is call the StopAnimationFunction
...
});
});
//StopAnimationFuncton
$('#Loading').stop(true,false).delay(1000).fadeOut(500,function(){
$(this).remove();
$("#BackGroundDiv").stop(true,false).animate({opacity:0.0},1000,function(){
ShopperPortal.Content.Functions.Render.InitializeRenderModeContainerAndLoadingEffects.Parameters.IsStopLoadingEffectActive=false;
});
});
我的问题是,当用户在按钮上“点击”很多次时,当前的动画不会停止 . 我已尝试所有变体 - 使用stop(),stop('fx',true,false),stop(true,true),stop(true,false)为每个元素组合,但没有任何帮助 .
哪种方法可以阻止当前动画和完整功能?也 . 如果我的逻辑不正确,我会接受新想法吗?
编辑1:我使用的是jQuery版本1.8.2
EDID 2:我已经读过延迟(1000)可能会导致问题,因为它无法删除/取消 .
Jquery .delay().fadeOut cancel/clear queue.. Is it possible? How?
http://forum.jquery.com/topic/stop-does-not-clear-delay
这就是为什么我用动画取代它({opacity:1.0},1000)但没有改变 .
1 回答
如果在同一元素上调用多个动画方法,则后面的动画将放置在元素的效果队列中 .
这些动画直到第一个动画完成才会开始 .
调用
.stop()
时,队列中的下一个动画立即开始 .如果
clearQueue
参数的值为true
,则队列中的其余动画将被删除,并且永远不会运行 .