Loading Please Wait...

Logo Lynxsia IT Solutions

jQuery Effects Animation

JQ Effects Animation

With jQuery, you can create custom animations.

The animate() Method

The animate() method is used to create custom animations.

Syntax
					 
        
          $(selector).animate({params}, speed, callback);
        
      

The required params parameter defines the CSS properties to be animated.

The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is a function to be executed after the animation completes.

The following example demonstrates a simple use of the animate() method; it moves a element to the right, until it has reached a left property of 250px:

					 
        
          $("button").click(function(){
            $("div").animate({left: '250px'});
          });
        
      
By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!
jQuery animate() - Manipulate Multiple Properties

We can animate multiple properties at the same time.

					 
        
          $("button").click(function(){
            $("div").animate({
              position: 'absolute',
              left: '250px',
              opacity: '0.5',
              height: '150px',
              width: '150px',
              paddingLeft: '10px'
            });
          }); 
        
      
jQuery animate() - Using Relative Values

It is also possible to define relative values (the value is then relative to the element's current value). This is done by putting += or -= in front of the value.

					 
        
          $("button").click(function(){
            $("div").animate({
              left: '250px',
              height: '+=150px',
              width: '+=150px'
            });
          }); 
        
      
jQuery animate() - Using Pre-defined Values

You can even specify a property's animation value as "show", "hide", or "toggle".

					 
        
          $("button").click(function(){
            $("div").animate({
              height: 'toggle'
            });
          }); 
        
      
jQuery animate() - Uses Queue Functionality

By default, jQuery comes with queue functionality for animations.

This means that if you write multiple animate() calls after each other, jQuery creates an "internal" queue with these method calls. Then it runs the animate calls ONE by ONE.

So, if you want to perform different animations after each other, we take advantage of the queue functionality:

					 
        
          $("button").click(function(){
            var div = $("div");
            div.animate({height: '300px', opacity: '0.4'}, "slow");
            div.animate({width: '300px', opacity: '0.8'}, "slow");
            div.animate({height: '100px', opacity: '0.4'}, "slow");
            div.animate({width: '100px', opacity: '0.8'}, "slow");
          }); 
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved