Skip to content

Instantly share code, notes, and snippets.

@prggmr
Created April 13, 2012 15:42
Show Gist options
  • Save prggmr/2377804 to your computer and use it in GitHub Desktop.
Save prggmr/2377804 to your computer and use it in GitHub Desktop.
jQuery click and hold function
$.fn.click_hold = function(fn, delay) {
var timeout = 0;
$(this).live("mousedown", function(evt) {
var $this = $(this).data("mousedown", true);
timeout = setInterval(function() {
if ($this.data("mousedown") === true) {
console.log("held");
fn(evt);
} else {
console.log("released");
clearInterval(timeout);
}
}, delay);
});
$(this).live("mouseup", function(evt) {
$(this).data("mousedown", false);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment