jQuery queue() get queue

Description

jQuery queue() get queue

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*  w ww .  j  av  a2 s .  c o m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    let div = $("div");
    startAnimation();
    showQueue();

    function startAnimation(){
      div.animate({height: 300}, "slow");
      div.animate({width: 300}, "slow");
      div.animate({height: 100}, "slow");
      div.animate({width: 100}, "slow",startAnimation);
    }

    function showQueue(){
      let q = div.queue();
      $("span").text(q.length);
      setTimeout(showQueue);
    }
  });
});
</script>
</head>
<body>

<button>Start Animation</button>

<p>The queue length is: <span></span></p>

<div style="width:50px;height:50px;position:absolute;left:10px;top:100px;background-color:red;"></div>

</body>
</html>



PreviousNext

Related