JQuery Animations

The last article explained how we can JQuery slide effects to slide up and slide down html elements on the webpage. This article explains how JQuery animations work. JQuery contains animate() method which is used for creating amazing animations. The animate method takes three parameters. The first is the parameters for animation, the second is the speed and the third is callback. Last two parameters are optional. The animate method executes on the element which we want to animate. Take a look at the following example to see a simple animation in JQuery.

The above html page contains a button at the top center of the page and a blue circle under the button. This blue circle is a div with class circle. When you click on the button, an event is fired. JQuery click event handles this function. Inside the click event a function is located which animates the circle div by pushing it 400px down the page.If you click the button, you will see your blue circle moving down 400px. This is due to the animate function.

It is pertinent to mention here that by default html elements are statically positioned. Therefore, to move elements, mark them as absolute, fixed or relative using CSS properties

Animating Multiple Properties

In the last example, we animated the circle div via single property. Animate function can take multiple parameters for animating an html element. Have a look at the following example.