a tiny timer management plugin for jQuery
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().
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>
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.
});
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.
}
});
$.delayDo(
// type 'string': timer’s specific id (name).
'timerId',
// type 'function': function that is added to the timer’s queue.
function () {
// do something.
}
);
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.
}
});
Clear queue off a specific delayDo timer and destroy itself.
$.delayDo.cancel('timerId');
Clear all queues off delayDo timers and destroy themselves.
Yes, it‘s Buster Call.
$.delayDo.bustercall();
See the Pen delayDo Example 1 by Takehiko Ono (@onopko) on CodePen.
See the Pen delayDo Example 2 by Takehiko Ono (@onopko) on CodePen.
See the Pen delayDo Example 3 by Takehiko Ono (@onopko) on CodePen.