Javascript Ajax jQuery Html PHP Example Quiz New MORE

jQuery animate() method with example

The jQuery animate() method is used to add animation to HTML element using css properties.

Syntax:

$(selector).animate({styles},speed,easing,callback)

Example:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("#box").animate({width: "300px"});
  });
  $("#btn2").click(function(){
    $("#box").animate({width: "100px"});
  });
});
</script>
</head>
<body>
 
<button id="btn1">Animate Width</button>
<button id="btn2">Reset Width</button>
 
<div id="box" style="background:green;height:100px;width:100px;margin:6px;"></div>
 
</body>
</html>

Run it Yourself »