【问题标题】:jquery .animate different speedsjquery .animate不同的速度
【发布时间】:2009-12-14 16:45:31
【问题描述】:

我在 Jquery 中使用 .animate 函数。我有一个使用 marginLeft 滑过的 div,但我也需要它淡入,但我需要它比 marginLeft 效果慢。使用 .animate,我似乎只能应用一个速度参数。

<script type="text/javascript">
 $(document).ready(function(){
 $(".topFrameAnim").css("opacity", "0.0");
  $(".topFrameAnim").animate({
  marginLeft: "0",
    }, 500 );

    $(".topFrameAnim").animate({
  opacity: "1",
    }, 1000 ); // Need this effect to be applied at the same time, at a different speed.




    });


</script>

【问题讨论】:

    标签: jquery effects


    【解决方案1】:

    您需要使用animate的两个参数形式,在options数组中queue:false(在第一个动画上):

    <script type="text/javascript">
     $(document).ready(function(){
     $(".topFrameAnim").css("opacity", "0.0")
    
     .animate({
      marginLeft: "0",
        }, { queue: false, duration: 500 })
      .animate({
      opacity: "1",
        }, 1000 ); // Need this effect to be applied at the same time, at a different speed.
    
        });
    
    
    </script>
    

    注意:这里的 .animate 是为了减少使用的选择器的数量。由于您选择的是相同的对象,因此最好重用现有的对象。

    【讨论】:

    • 谢谢你,这正是我想要的!
    • 我不想成为一个混蛋,但对于像我这样的未来菜鸟,我只想补充一点,你缺少一个花括号。应该是这样的... }, { queue: false, duration: 500 } ).... 仅供参考。顺便说一句,干得好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多