Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript Animation

Introduction to JavaScript Animation

JavaScript Animation is used to make the object changed from one state to other state or moved from one position to other position by providing some special functionality through the code. This animation can be fade effect, roll-in or roll-out, page-in or page-out, object movements By default JavaScript provides default animation library that is Script.Aculo.us. Animation can also be used to move the HTML elements like ,

,

,

etc. around the page according to the provided functionality to the code.

Advantages

  • JavaScript animation make the immovable object to the movable.
  • Used to develop the games.

How does Animation work in JavaScript?

Animation worked based on functions provided to animate the object. You can consider below frequently used functions for animation.

  • setTimeout( function, time) : This function executes the operation after provided duration of milliseconds from now.
  • setInterval(function, time): This function executes the operation after every provided duration of milliseconds.
  • clearTimeout(time): This function executes for clears the any timer set by the setTimeout() functions.

JavaScript also used for set the number of attributes of any element and also includes its position on the screen. We can also set the top and the left attribute of an object to position this object on anywhere on the screen.

Syntax:

var var= setInterval(getMyFun, 5);
function getMyFun() {
if (condition) {
clearInterval(var);
} else {
//required logic
}
}

Note: We can also write our own custom functionality for our own animation.

Examples of JavaScript Animation

Below are the examples of Javascript Animation :

Example #1 – Moving the Image Right

Code:



JavaScript Animation






Introduction to JavaScript Animation


Moving the Image Right hand side by clicking the button


JavaScript animation is used to make the object changed from one
state to other state or moved from one position to other position by
providing some special functionality through the code. This animation
can be fade effect, roll-in or roll-out, page-in or page-out, object
movements etc. By default JavaScript provides default animation
library that is Script.Aculo.us. JavaScript animation can also be used
to move the HTML elements like img, div , p, footer tags etc. around
the page according to the provided functionality to the code.









Output:

After Clicking Move Right button:

Example #2 – Moving the content left

Code:



JavaScript Animation






Introduction to JavaScript Animation


Moving the Content Right hand side by clicking the button



JavaScript animation is used to make the object
changed from one state to other state or moved from one position to
other position by providing some special functionality through the
code. This animation can be fade effect, roll-in or roll-out, page-in
or page-out, object movements etc. By default JavaScript provides
default animation library that is Script.Aculo.us. JavaScript
animation can also be used to move the HTML elements like img, div ,
p, footer tags etc. around the page according to the provided
functionality to the code.







Output:

After Clicking the Move Left Button:

Example #3 – Mouse hover change Image

Code:



JavaScript Animation




Introduction to JavaScript Animation


JavaScript animation is used to make the object
changed from one state to other state or moved from one position to
other position by providing some special functionality through the
code. This animation can be fade effect, roll-in or roll-out, page-in
or page-out, object movements etc. By default JavaScript provides
default animation library that is Script.Aculo.us. JavaScript
animation can also be used to move the HTML elements like img, div ,
p, footer tags etc. around the page according to the provided
functionality to the code.


Hover Cursor on to the image to see the other image


onMouseOut="document.myImage.src = firstImage.src;"> name="myImage" src="n1.jpg" />


Output:

After hovering the cursor on to the Image

Conclusion

JavaScript animation is used to make the object movable or change its style. Animation can work with paragraph, header, images, footer or any html element tags. We can also apply time intervals to the application.

Recommended Articles

This is a guide to JavaScript Animation. Here we discuss how does Animation works in JavaScript along with respective programming examples. You may also have a look at the following articles to learn more –

  1. JavaScript FileReader
  2. JavaScript Get Element by Class
  3. Email Validation in JavaScript
  4. JavaScript String to Number

The post JavaScript Animation appeared first on EDUCBA.



This post first appeared on Free Online CFA Calculator Training Course | EduCB, please read the originial post: here

Share the post

JavaScript Animation

×

Subscribe to Free Online Cfa Calculator Training Course | Educb

Get updates delivered right to your inbox!

Thank you for your subscription

×