Last active
August 29, 2015 14:15
-
-
Save chsh/a087f74a93d2dcbfabb3 to your computer and use it in GitHub Desktop.
example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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