Skip to content

Instantly share code, notes, and snippets.

@devcem
Created March 20, 2015 18:33
Show Gist options
  • Save devcem/fe0c1ca2a216a3f34a26 to your computer and use it in GitHub Desktop.
Save devcem/fe0c1ca2a216a3f34a26 to your computer and use it in GitHub Desktop.
Just click
var lastEvent;(function($) {$.fn.justClick = function(callback) {this.bind('mousemove mousedown mouseup', function(e) {if(e.type == 'mouseup' && lastEvent == 'mousedown'){callback()}lastEvent = e.type;});}}(jQuery));
$('#obj').justClick(function(){
console.log("Not move, not drag. It is just click!");
});
//Similar threads
//http://stackoverflow.com/questions/1572483/jquery-mousedown-mousemove
//http://stackoverflow.com/questions/2928161/binding-mousemove-within-mousedown-function-with-jquery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment