![]() |
JavaScript is a very powerful scripting language. We can create animations in JavaScript using some CSS properties on the DOM elements. In this article, we will create some animations using JavaScript. We can use the following methods to create animations using JavaScript: Table of Content Creating animation using the setTimeout() methodThe setTimeout() method can be used to call the animation function once after the given time. We can use it with an event and make it call the callback function every time the event occurs. Syntax:setTimeout(callback_function, delay_time);
Example: The below example implements the setTimeout() method to create a JavaScript animation. HTML
Output: Creating animation using the setInterval() methodThe setInterval() method can be used to create the infinite animations that runs automatically and infinitely. It also takes a callback function and repeatedtly calls it after the given delay time. Syntax:setInterval(callback_function, delay_time);
Example: The below example uses the setInterval() method to create animation using JavaScript. HTML
Output: Creating animation by using style propertyThe style property can be used to add some inline styles to an element. We can use this property with a event to add and remove styles on the occurrence of the event. Syntax:element.style.css_property_name = value
Example: In the below code, we will use the style property to create an animation using JavaScript. HTML
Output: |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |