What are queues in jQuery?

前端 未结 6 571
萌比男神i
萌比男神i 2020-11-22 01:09

I found the jQuery.com document on queue()/dequeue() is too simple to understand. What exactly are queues in jQuery? How should I use them?

6条回答
  •  别那么骄傲
    2020-11-22 01:55

    It allows you to queue up animations... for example, instead of this

    $('#my-element').animate( { opacity: 0.2, width: '100px' }, 2000);
    

    Which fades the element and makes the width 100 px at the same time. Using the queue allows you to stage the animations. So one finishes after the other.

    $("#show").click(function () {
        var n = $("div").queue("fx");
        $("span").text("Queue length is: " + n.length);
    });
    
    function runIt() {
        $("div").show("slow");
        $("div").animate({left:'+=200'},2000);
        $("div").slideToggle(1000);
        $("div").slideToggle("fast");
        $("div").animate({left:'-=200'},1500);
        $("div").hide("slow");
        $("div").show(1200);
        $("div").slideUp("normal", runIt);
    }
    runIt();
    

    Example from http://docs.jquery.com/Effects/queue

提交回复
热议问题