The .animate() method in jQuery is used to handle effects and animations. Properties which have numeric values can be animated by this method such as width, height, border-width etc. however, the property names should be camel cased( eg. borderWidth). Usually, if different animations are chained on the same html element, jQuery adds them to a queue and they are executed sequentially. In this article, we will discuss how we can make such animations simultaneously. The animate() method will only trigger after the event (being listened to) occurs on the page. For two different HTML elements, on triggering of an event, the animations will occur simultaneously.
According the official jQuery documentation, the .animate() method offers two prototypes:
The following code demonstrates how chaining animations would look like:
In the above example, we have chained three animations to the HTML button element. The animations trigger on click. The same would’ve happened for the following set of code:
We can cause the animations to trigger simultaneously in two ways.
Method 1: Using ‘QUEUE’ Property in options
By passing the option
queue : false, we ensure that the animations do not get added to the queue. The default animation queue in jQuery is called fx. The above method is especially useful when you want certain animations to happen simultaneously and certain animations to occur sequentially with better readability of code. By default, queue is true.
Method 2: Passing all the css properties in a single object
Through the above two methods, the task of implementing two or more animations in jQuery can be implemented simultaneously as opposed to placing them in the queue and executing them sequentially.
- jQuery | Stop Animations
- Opening google search results simultaneously in new tabs in Chrome
- CSS | Animations
- AngularJS | Animations
- Android Animations in Kotlin
- How to dynamically create '@-Keyframe' CSS animations?
- Android Rotate animations in Kotlin
- Run Python script from Node.js using child process spawn() method
- Create a web server and run PHP script on it using Raspberry Pi
- Why is Java 'write once and run anywhere'?
- How to run Cron Jobs in Node.js ?
- How to Run Synchronous Queries using sync-sql Module in Node.js ?
- Docker compose tool to run multi container applications
- How to Make, Save, and Run a Simple VBScript Program?
- Run Python Script using PythonShell from Node.js
- jQuery | jQuery.fx.interval Property with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.