delayDo

a tiny timer management plugin for jQuery

Fork me on GitHub

delayDo is a tiny jQuery plugin. It enables you to create a specific timer which contains some functions as a queue and can resume it later.

Also delayDo is friendly for modern browsers. Its delay method uses requestAnimationFrame() and performance.now() instead of setTimeout() and Date.now().

Usage

  1. Include jQuery, setAnimationFrameTimeout and delayDo.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script src="setAnimationFrameTimeout.min.js"></script>
    <script src="delayDo.min.js"></script>
  2. Initialize a timer (just name a specific timer id) and add functions to its queue.

    for (var i =0; i < 10; i++) {
        $.delayDo('timerId', function () {
            // do something.
        });
    }

    OR

    $.delayDo('timerId', function () {
        // do something.
    });
    $.delayDo('timerId', function () {
        // do another.
    });
  3. Resume the timer. It calls a function from its queue one by one at regular intervals.

    $.delayDo.resume({
        timerId: 'timerId',
        interval: 200,
        complete: function () {
            // do something.
        }
    });

Initialize a timer

and add functions to its queue

$.delayDo(
    // type 'string': timer’s specific id (name).
    'timerId',

    // type 'function': function that is added to the timer’s queue.
    function () {
        // do something.
    }
);

Methods

$.delayDo.resume()

Resume a specific delayDo timer.

$.delayDo.resume({
    timerId: 'timerId',

    // type 'number'
    // unit 'millisecond'
    // Functions in the queue of delayDo timer is executed one by one at this interval.
    interval: 200,

    // type 'number'
    // unit 'millisecond'
    // This method will be called after this property’s value.
    delay: null,

    // type 'function'
    // This is executed after that the queue of delayDo timer became empty.
    complete: function () {
        // do something.
    }
});

$.delayDo.cancel()

Clear queue off a specific delayDo timer and destroy itself.

$.delayDo.cancel('timerId');

$.delayDo.bustercall()

Clear all queues off delayDo timers and destroy themselves.
Yes, it‘s Buster Call.

$.delayDo.bustercall();

Examples

Example 1: Animation with single timer

See the Pen delayDo Example 1 by Takehiko Ono (@onopko) on CodePen.

Example 2: Animation widh multiple timer

See the Pen delayDo Example 2 by Takehiko Ono (@onopko) on CodePen.

Example 3: Masonry Appended with timer

See the Pen delayDo Example 3 by Takehiko Ono (@onopko) on CodePen.