Animation in JavaScript
You can use JavaScript to create a complex, unlimited effect.
You can use JavaScript to create a complex, unlimited effect, with the following elements:
- Fireworks
- Fade Effect
- Roll-in or Roll-out
- Page-in or Page-out
- Object movements
You should consider the existing effects library built on JavaScript: Script.Aculo.us .
This tutorial provides you with a basic understanding of how to use JavaScript to create an effect.
JavaScript can be used to move several DOM elements (
,
JavaScript provides the following two functions that are used frequently in animation programs.
- setTimeout (function, duration) - This function calls the Function after the duration (in milliseconds) from now.
- setInterval (function, duration) - This function calls the function after each duration (in milliseconds).
- clearTimeout (setTimeout_variable) - This function removes any timer set by the setTimeout () function.
JavaScript can also set some properties of a DOM object including its position on the screen. You can set the top and left properties of an object to determine its position anywhere on the screen. Here is the syntax:
// Set distance from left edge of the screen. object . style . left = distance in pixels or points ; or // Set distance from top edge of the screen. object . style . top = distance in pixels or points ;
Hand operation animation
We now implement a simple animation using DOM object attributes and JavaScript functions as follows. The following lists the various DOM methods:
We are using the getElementById () function to get a DOM object and then assign it to a Global variable, imgObj .
We have defined an initialization function init () to initialize imgObj , where we have set its position and left properties.
We are calling the initialization function at the time of loading the window.
Finally, we are calling moveRight () function to increase the left distance by 10 pixels. You can also set it to a negative value to move it to the left.
For example
Try the following example:
JavaScript Animation
- How to Print Double Quotes in Java
- How to Create an Executable File from Eclipse
- How to Enable Webgl
- How to Create a Javascript Console in Sublime Text
- How to Close a Window in Java
- How to Print an Array in Java
- Introduction to 2D Array - 2-dimensional array in JavaScript
- How to Run Program C/C++ Program in Netbeans
- How to Enable JavaScript in Mozilla Firefox
- How to Check Null in Java
-
How to rank in Excel using the RANK function - Ranking from highest to lowest.
-
How to use the PRODUCT function in Excel - A function to calculate the product of values.
-
COUNTIF function: Conditional counting in Excel
-
The T.DIST.2T function in Excel
-
What is the TRUNC function in Excel? How to use the function?
-
The STOCKHISTORY function in Excel