Call function for each animation step - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:animate

Description

Call function for each animation step

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn").click(function(){
    $("#box").animate({
      width: "400px"
    }, {//from w  w w.j  a v  a  2s  .  c o m
      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:#98bf21;height:50px;width:1px;border:1px solid green;"></div>
</div>

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

</body>
</html>

Related Tutorials