Javascript JQuery animate()-停止所有动画
我有一个关于停止多个动画的问题,下面有一些伪代码来说明我的情况: CSSJavascript JQuery animate()-停止所有动画,javascript,jquery,css,Javascript,Jquery,Css,我有一个关于停止多个动画的问题,下面有一些伪代码来说明我的情况: CSS #aDiv { position: absolute; background-image: url("gfx/nyancat.png"); width: 46px; height: 50px; background-size: 55%; background-position: center center; background-repeat: no-repeat;
#aDiv
{
position: absolute;
background-image: url("gfx/nyancat.png");
width: 46px;
height: 50px;
background-size: 55%;
background-position: center center;
background-repeat: no-repeat;
}
JQUERY
function doAnimate(aDiv)
{
$(aDiv).animate({ //do stuff for first animation
height: (H*2)+"px",
width: (W*2)+"px",
left: "-="+(W*0.5)+"px",
top: "-="+(W*0.5)+"px",
opacity: 1
}, 500 , "linear", function()
{ $(aDiv).animate( //do stuff for second animation
{
height: H+"px",
width: W+"px",
left: "+="+(W*0.5)+"px",
top: "+="+(H*0.5)+"px",
opacity: 0.01
}, 500, function()
{ //call itself
doAnimate( aDiv );
}
);
}
);
}
//somewhere else in the code
doAnimate(aDiv);
当我在aDiv($(aDiv).stop())
上调用stop()
函数时,这会停止两个动画吗?我问这个问题的原因是因为我有一个动画div,它在窗口加载时被调用,但是在调用stop然后重新启动动画时,动画不会像以前那样运行,所以我必须刷新页面。谢谢
编辑:仅使用.stop()即可满足我的要求。我使用的是JQuery 1.7,因此.finish()功能对我不可用。对于我的问题,将背景大小css值从auto更改为原始值(在我的例子中为55%)似乎已经解决了这个问题 可能您正在寻找
.finish()
或.stop(true,true)代码>:创建一个小提琴请抱歉,我的道歉-