Reputation: 46479
I'm firing an onClick event and would like to somehow check if it was just a click or if it was held down for some time before releasing mouse button and actually firing a click event.
reason for this is to either perform a myTest()
function so onClick="myTest()"
that simply console logs either "mouse was clicked" or "mouse was held and clicked" depending on what action user performs.
Upvotes: 1
Views: 2328
Reputation: 316
You should do below code:
var timeout, clicker = $('#clicker');
var count = 0;
clicker.mousedown(function(){
timeout = setInterval(function(){
clicker.text(count++);
}, 500);
return false;
});
$(document).mouseup(function(){
clearInterval(timeout);
return false;
});
You can hold the mouse on the square and the enter code here count interval is 500 miliseconds.
you can change it as per your requirements
Hope this will help you.
Upvotes: 3