Effet jQuery - méthode animate ()

La description

le animate( ) La méthode effectue une animation personnalisée d'un ensemble de propriétés CSS.

Syntaxe

Voici la syntaxe simple pour utiliser cette méthode -

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

Paramètres

Voici la description de tous les paramètres utilisés par cette méthode

  • params - Une carte des propriétés CSS vers lesquelles l'animation se dirigera.

  • duration - Il s'agit d'un paramètre facultatif représentant la durée de fonctionnement de l'animation.

  • easing - Il s'agit d'un paramètre facultatif représentant la fonction d'accélération à utiliser pour la transition.

  • callback - Il s'agit d'un paramètre facultatif représentant une fonction à appeler une fois l'animation terminée.

Exemple

Voici un exemple simple montrant l'utilisation de cette méthode -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.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>

Cela produira le résultat suivant -

jquery-effects.htm