Skip to content

Instantly share code, notes, and snippets.

@chsh
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save chsh/a087f74a93d2dcbfabb3 to your computer and use it in GitHub Desktop.

Select an option

Save chsh/a087f74a93d2dcbfabb3 to your computer and use it in GitHub Desktop.
example
/* usage
if (!$.looper.is_running()) {
$.looper.initialize({
action: function() {
$('#notification-marker')
.animate({opacity: 1}, 800)
.animate({opacity: 0}, 800);
},
timeout: 1600
});
}
*/
(function($) {
var running = false;
var settings = null;
var defaults = {
action: null,
timeout: null,
on_start: null,
on_stop: null
};
var initialize = function(options) {
settings = $.extend(defaults, options);
return this;
};
var start = function() {
running = true;
run();
};
var stop = function() {
running = false;
};
var run = function() {
if (running) {
settings.action();
setTimeout(run, settings.timeout);
}
};
var is_running = function() { return running; };
$.looper = {
initialize: initialize,
start: start, stop: stop, is_running: is_running
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment