Skip to content

Instantly share code, notes, and snippets.

@mrkmg
Created October 4, 2011 20:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkmg/1262680 to your computer and use it in GitHub Desktop.
Save mrkmg/1262680 to your computer and use it in GitHub Desktop.
jQuery On Hold event
(function( $ ){
$.fn.onHold= function(time,action) {
this.data('onHold_selected',false);
this.mousedown(function(){
$(this).data('onHold_selected',true);
var object = this;
setTimeout(function(){
if($(object).data('onHold_selected')){
action();
}
},time);
});
this.mouseup(function(){
$(this).data('onHold_selected',false);
});
return this;
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment