jQuery animate() with step function

Description

jQuery animate() with step function

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   w w w . ja v  a2 s  .co m
<script>
$(document).ready(function(){
  $("#btn").click(function(){
    $("#box").animate({
      width: "400px"
    }, {
      duration: 5000,
      easing: "linear",
      step: function(x) {
        $("#demo").text(Math.round(x * 100 / 400)  + "%");
      }
    });
  });
});
</script>
</head>
<body>

<button id="btn">Start Progress Bar</button>

<div style="border:1px solid green;margin:10px;width:400px;">
  <div id="box" style="background:red;height:50px;width:1px;border:1px solid green;"></div>
</div>

<p id="demo"></p>

</body>
</html>



PreviousNext

Related