【问题标题】:Changing speed (duration) on animation/stop改变动画/停止的速度(持续时间)
【发布时间】:2012-01-25 09:20:05
【问题描述】:

环顾四周,找不到答案。我需要在这段代码中添加动画的持续时间:

$('a:has(.image-active)').hover(function() { 
    $('.image-active', this).stop().animate({"opacity": 1}); 
},function() { 
    $('.image-active', this).stop().animate({"opacity": 0}); 
});

但是,我不知道在哪里放置持续时间。刚才它淡入 1 淡出到 0,这一定是 jQuery 的默认值。

【问题讨论】:

标签: javascript jquery performance duration


【解决方案1】:

.animate() 有一个参数对象:

.animate({"opacity": 1}, {duration: 100});

我喜欢冗长,但您也可以将持续时间作为数字传递:

.animate({"opacity": 1}, 100);

阅读documentation 了解更多选项。看例子。

【讨论】:

    【解决方案2】:

    将持续时间作为第二个参数传递给 animate(),例如:

    .animate({"opacity": 1}, "fast");
    

    .animate({"opacity": 1}, 3000);
    

    【讨论】:

      【解决方案3】:

      jquery API for the .animate() method 是一个很好的起点。您可以在属性之后为动画指定持续时间(以毫秒值或“快”或“慢”字符串的形式)。如果我没记错的话,默认值为 400。

      【讨论】:

        【解决方案4】:

        首先opacity不应该在quotes更改"opacity"opacity

        .animate({opacity: 1},100);
        

        参考here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-19
          相关资源
          最近更新 更多