jQuery会动画多少步? [英] How many steps does jQuery animate in?
问题描述
我正在编写自己的动画函数,以获取乐趣和内容.
I'm writing my own animate function for fun and stuff.
虽然我真的无法获得流畅的动画.jQuery每个动画的步数比例非常好,使其变得非常流畅,我想知道它们用来确定要执行多少步的通用公式是什么.
I can't really get a smooth animation to occur though. jQuery has an awesome ratio of steps per animation making it really smooth, I was wondering what is the general formula they use to figure out how many steps to take.
推荐答案
这取决于动画的持续时间.jQuery使用存储在 jQuery.fx.interval
中的默认设置,在第一个动画启动时启动所有动画共有的单个13毫秒间隔计时器,并在所有动画完成后将其停止.
It depends on the duration of the animation. jQuery, using its default setting stored in jQuery.fx.interval
, starts a single 13 ms interval timer common to all animations when the first one is started and stops it once all have completed.
在 custom:
, interval:
和 step:
="http://bit.ly/jquery-source" rel ="nofollow">未压缩的jQuery源代码.其中的最后一个包含逻辑,该逻辑确定基于时间戳的已运行动画的比例:纯JS中的 new Date().getTime()
.
Search for animate:
, custom:
, interval:
, and step:
in the unminified jQuery source code. The last of these contains the logic that determines the fraction of the animation that has already run, which is based on timestamps: new Date().getTime()
in pure JS.
从理论上讲,它的速率约为80帧/秒,比当今大多数LCD监视器的60 Hz刷新速率快.如果性能有问题,您可以通过降低帧速率(增加间隔)来解决.
This theoretically yields about 80 frames/s, faster than the 60 Hz refresh rate of most of today's LCD monitors. You could probably get by with dropping the frame rate a bit (increasing the interval) if performance is a problem.
这篇关于jQuery会动画多少步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!