撤消 JavaScript 动画

undoing javascript animation

本文关键字:动画 JavaScript 撤消      更新时间:2023-09-26

我正在某个窗格上放大轮播的div。要放大窗格,我这样做:

if(currentPane==2)
{
    $("#carousel").animate({height:320},1000);
    $("#carousel").animate({top:411},1000);
    $("#dropShadow").animate({top:731},1000);
}

这非常有效。离开此窗格时,我想再次将轮播返回到较小的尺寸,我这样做:

if(currentPane==3)
{
    $("#dropShadow").animate({top:672},1000);
    $("#carousel").animate({top:411},1000);
    $("#carousel").animate({height:100},1000);
}

阴影返回到其原始位置,但旋转木马拒绝减小大小。

对我来说,我似乎使用相同的代码,所以不明白为什么它不起作用。

你有没有尝试过添加一个.stop()?比如:只是一个想法不是 100% 确定,让 JSFIDDLE

if(currentPane==3)
{
    $("#dropShadow").stop(true).animate({top:672},1000);
    $("#carousel").stop(true).animate({top:411},1000);
    $("#carousel").stop(true).animate({height:100},1000);
}