问题
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