I do not see anything in your code, checking the time difference. In most libraries (jQuery, MooTools, etc.) Animation is set up depending on the time.
jQuery uses the step
method, which is used to determine the next value for the effect. To look at this feature, open the jQuery version (without compression) and search for jQuery.fx.prototype
. This block of code contains the step
method.
Suppose you want to say that an element moves from one position to another. It looks like your code will repeat until a fixed number of animations are set. Thus, you strictly observe the number of iterations, not the time. Browsers often lag behind. Someone can run all kinds of garbage on their machine, which will slow down your execution. And then the overall execution of your animation will be longer than expected, and the animation itself will be a "jerk."
So, what you have to do is be strict with time, and not try to apply even steps. Each time you βstepβ through an animation, you must consider the start time of the animation, the total end time of the animation, and the downtime. With this, you can determine where the animation should be. Therefore, if you want to move an element (linearlly) from position 100 to 200 in 10 seconds, and we are in 7.5 seconds, you know that the position should be 175. Then, as soon as the time is at or for completed 10 seconds, You set this to 200 and kill the loop.
JQuery code will be a little hard to read due to the easing effects it uses and all the internal hooks and callbacks. But the idea is pretty straightforward.
source share