Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jQuery accomplish its asynchronous animations?

...or more specifically, how are they able to create animations via javascript, which is synchronous, without holding up the next javascript statement.

It's just a curiosity. Are they using a chain of setTimeout()? If so, are they set early, each one with a slightly longer duration than the previous, and running parallel? Or are they being created through a recursive function call, therefore running in series?

Or is it something completely different?

like image 620
user113716 Avatar asked Mar 03 '10 13:03

user113716


People also ask

How can jQuery be used to create animations?

The animate() method performs a custom animation of a set of CSS properties. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect. Only numeric values can be animated (like "margin:30px").

Is jQuery asynchronous?

You can use jQuery to support both synchronous and asynchronous code, with the `$. when` function, and your code doesn't have to care whether or not it's async.

Is jQuery used for animation?

With jQuery, you can create custom animations.

What is the default easing used for jQuery animation?

An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing , and one that progresses at a constant pace, called linear .


1 Answers

There is an alternative to setTimeout() called setInterval() which will call the function you pass as argument at regular intervals. Calling setInterval will return a value which can be passed to clearInterval to stop the function from being called.

like image 114
Marius Avatar answered Nov 02 '22 23:11

Marius