queue() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:queue

Description

The queue() method returns the effect queue for the selected elements.

Syntax

$(selector).queue(queueName);
Parameter Require Description Value
queueName Optional. name of the queue Default is "fx", the standard effects queue

The following code shows how to Display the length of a queue in a <span> element:

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(){
    $("button").click(function(){
        var div = $("div");
        startAnimation();/*from   w ww.jav a 2 s .  co  m*/
        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(){
            var 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>

Related Tutorials