【问题标题】:jQuery catch when animation is finished动画完成时的jQuery捕获
【发布时间】:2011-04-09 17:12:27
【问题描述】:

我正在使用color plugin(链接到 google 缓存,jquery.com 目前已关闭)来处理背景颜色动画。

$(".navigation a").hover(
    function(){
        $(this).stop().animate({backgroundColor: black});
    },
    function(){
        $(this).stop().animate({backgroundColor: green});
        $(this).hide();
    }
);

动画完成后需要隐藏当前链接。现在它立即隐藏,在mouseout()

解决办法是什么?

【问题讨论】:

    标签: jquery colors background animation


    【解决方案1】:

    需要将.hide()放入.animate()调用的回调函数中。

    $(this).stop().animate(
        {backgroundColor: green},
        function() {
            $(this).hide();
        }
    );
    

    【讨论】:

      【解决方案2】:

      通过给.hide() 一个持续时间,它将被添加到动画队列中。

      所以你可以这样做:

      $(this).stop().animate({backgroundColor: green}).hide( 0 );
      

      【讨论】:

      • +1 这适用于“可补间”动画(背景颜色不是一种,但这不是你的错)。非常聪明,真的:-)
      • @Andy E - 谢谢。 :o) 如果你有 jQueryUI,你可以为 backgroundColor 设置动画。 jsfiddle.net/mfJhH tweenable 就是这个意思吗?
      • 是的,我不知道。这很整洁,谢谢:-)
      • 哎呀-我举了另一个答案的例子。这是我的。 jsfiddle.net/mfJhH/1
      猜你喜欢
      • 2012-12-29
      • 2010-12-18
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多