Tutorials Point


  jQuery Tutorial
  jQuery UI
  jQuery References
  jQuery Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

jQuery Effect - animate() Method


previous next AddThis Social Bookmark Button


Advertisements

Description:

The animate( ) method performs a custom animation of a set of CSS properties.

Syntax:

Here is the simple syntax to use this method:

selector.animate( params, [duration, easing, callback] );

Parameters:

Here is the description of all the parameters used by this method:

  • params: A map of CSS properties that the animation will move toward.

  • duration: This is optional parameter representing how long the animation will run.

  • easing: This is optional parameter representing which easing function to use for the transition

  • callback: This is optional parameter representing a function to call once the animation is complete.

Example:

Following is a simple example a simple showing the usage of this method:

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
    $(document).ready(function() {

      $("#out").click(function(){
         $("#block").animate({ 
           width: "70%",
           opacity: 0.4,
           marginLeft: "0.6in",
           fontSize: "3em", 
           borderWidth: "10px"
         }, 1500 );
      });
      $("#in").click(function(){
         $("#block").animate({ 
           width: "100",
           opacity: 1.0,
           marginLeft: "0in",
           fontSize: "100%", 
           borderWidth: "1px"
         }, 1500 );
      });

   });
   </script>
   <style>
      div {
           background-color:#bca;
           width:100px; 
           border:1px solid green; 
          }
  </style>
</head>
<body>

   <p>Click on any of the buttons</p>
   <button id="out"> Animate Out </button>
   <button id="in"> Animate In</button>
   <div id="block">Hello</div>
  
</body>
</html>

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements