Differentiate click vs mousedown/mouseup
onMouseDown will trigger when either the left or right (or middle) is pressed. Similarly, onMouseUp will trigger when any button is released. onMouseDown will trigger even when the mouse is clicked on the object then moved off of it, while onMouseUp will trigger if you click and hold the button elsewhere, then release it above the object.
onClick will only trigger when the left mouse button is pressed and released on the same object. In case you care about order, if the same object has all 3 events set, it's onMouseDown, onMouseUp, then onClick. Each even should only trigger once though.
Details:
- http://api.jquery.com/click/
- http://api.jquery.com/mouseup/
- http://api.jquery.com/mousedown/
Here's one approach
- set a variable to true
- make a function that will set it to false when called
- have a timer (
setTimeout()
) start counting down on mousedown() - on mouseup, clear the timeout, and check if it the variable is true or false
- if it is false, call the function you want to happen on click
- In any case, set the variable back to true
This will do what you want. Here's a jsfiddle showing how it might work: http://jsfiddle.net/zRr4s/3/