【问题标题】:Auto-start jQuery custom queue自动启动 jQuery 自定义队列
【发布时间】:2014-04-25 23:10:56
【问题描述】:

As explained in another question,If the queue being queued is fx and the queue is not already in progress, dequeue is called.。

默认队列足够智能,可以自动启动,这很好。 但是如何为我的自定义队列复制相同的功能,即队列为空时自动启动?

我的问题是我收到了 Pusher 调用(页面上的 ajax 调用),这些调用激活了下面的代码以将新名称添加到 #tickerlist。问题是,要启动队列,我必须在队列外添加.dequeue,然后强制tickerlistqueue 启动队列中的下一个项目。当您同时收到多个 Pusher 调用时,这实际上会使队列变得无用 - 作业只是相互运行,因为这正是我告诉它要做的事情。

基本上我需要的是仅在队列为空时运行.dequeue 行。否则,不要运行该行,队列会自行处理。

var tickerlist = $('#ticker-list');

tickerlist.queue('tickerlistqueue', function(next) {
    var name = 'John';
    $(name).hide().prependTo('#ticker-list').slideDown(700, function () {
        $('#ticker-list>div:last').remove();
        next();
    })
});

tickerlist.dequeue('tickerlistqueue'); //This is the only way to start the queue

【问题讨论】:

    标签: jquery queue jquery-queue


    【解决方案1】:

    呃;我的最后一段回答了我自己的问题。 jQuery shows you how to get the size of the queue in it's first example.

    如果队列 @9​​87654322@ 为 1 或更少,则启动队列。否则,不要做任何事情。它是 1,而不是 0,因为您在排队最新名称后调用它。

    特别是我的例子:

    if (tickerlist.queue('tickerlistqueue').length <= 1) {
        tickerlist.dequeue('tickerlistqueue');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 2016-01-28
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 2013-04-21
      • 2018-01-01
      相关资源
      最近更新 更多