Skip to content

Instantly share code, notes, and snippets.

@dmitry-ilyashevich
Created June 28, 2011 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry-ilyashevich/1050884 to your computer and use it in GitHub Desktop.
Save dmitry-ilyashevich/1050884 to your computer and use it in GitHub Desktop.
Timed event
(function($) {
var minimumTime = 1000; // minimum ms between events
var canFireEvent = true;
function myTimedEvent() {
if (canFireEvent) {
canFireEvent = false;
window.setTimeout(function() {
canFireEvent = true;
}, minimumTime);
executeFunction();
}
}
function executeFunction() {
console.log("executed at " + (new Date()).toString());
}
$(document).ready(function() {
$('button').click(myTimedEvent);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment