According to the jQuery documentation for .click(), the event is triggered only after this series of events:
I modified @adeneo's code a little bit, so it takes care of the problem where the user moves the cursor "just a little bit" and it should actually be interpreted as a click. I used eucledian distance for this. You could drop the Math.sqrt
for better performance, but then you have to adjust the radiusLimit
variable.
var left = 0,
top = 0,
radiusLimit = 5;
$(element).on({
mousedown: function(event) {
left = event.pageX;
top = event.pageY;
},
mouseup: function(event) {
var deltaX = event.pageX - left;
var deltaY = event.pageY - top;
var euclidean = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (euclidean < radiusLimit) {
console.log("this is a click.");
}
}
});