【问题标题】:.css().animate() not working?.css().animate() 不工作?
【发布时间】:2012-03-02 15:43:03
【问题描述】:

我想用这个来突出一个元素:

$('input.step:last').css('background','#003').animate({'background':'#fff'},300);

但它不起作用。

http://jsfiddle.net/Cpwmm/

为什么?

【问题讨论】:

    标签: jquery css jquery-animate


    【解决方案1】:

    要为颜色设置动画,您需要添加 jQuery Animate Colors 插件。

    http://www.bitstorm.org/jquery/color-animation/

    那么,你应该使用:

    $('input.step:last').css('background-color','#003')
                        .animate({'background-color':'#fff'},300);
    

    请注意,您应该为“背景颜色”属性而不是“背景”属性设置动画。

    http://jsfiddle.net/Cpwmm/7/

    【讨论】:

      【解决方案2】:

      您需要JQuery.Color 插件(jquery-ui 的一部分)。然后做,

      $(document).ready(function(){
           $('input.step:last')
           .css({'backgroundColor':'#003'})
          .animate({'backgroundColor':'#fff'},300);
      })​
      

      【讨论】:

        【解决方案3】:

        默认情况下,jQuery can’t animate colors。您可以使用jQuery.color() plugin, found here, 赋予它该功能。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-19
          • 2013-12-08
          • 2017-05-01
          • 1970-01-01
          相关资源
          最近更新 更多