How many steps does jQuery animate in?

耗尽温柔 提交于 2021-02-10 12:22:12

问题


I'm writing my own animate function for fun and stuff.

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.


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/4543279/how-many-steps-does-jquery-animate-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!