Last active
December 15, 2015 15:39
-
-
Save psdcoder/5283719 to your computer and use it in GitHub Desktop.
Simple jQuery timer. Usage: $('#timer').timer( 10, //duration of timer function(el){ //callback which will executed when time is up el.text('time is up!'); }
)
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
(function($){ | |
$.fn.timer = function(duration, callback) { | |
var time = duration, | |
element = this; | |
element.text(time--); | |
var interval = setInterval(function() { | |
if(time < 0){ | |
clearInterval(interval); | |
if(typeof callback === 'function'){ | |
callback(element); | |
} | |
}else{ | |
element.text(time); | |
time--; | |
} | |
}, 1000); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment