I need some way to find out when the user released the mouse button – something like keyUp – but for the mouse…
Any ideas?
PS: I want to mimic: active pseudo-class and my idea was to do something() on mouse press, and UnDoSomething() on mouse button up … now … if you got a better solution – hit me up! 🙂
The event is
onmouseup: http://www.w3schools.com/jsref/event_onmouseup.aspOr
mouseupif you’re calling element.addEventListener or using one of the JavaScript frameworks that drop the “on” part of the name.Update:
If you want to listen for any mouse up event, you’ll need to register an onmouseup listener on the page body in your onmousedown callback, and then unregister the onmouseup listener from within the onmouseup callback (so it only happens once).
If you’re using jQuery, this can be accomplished with the one() function.
Of course, if the user moves their mouse outside of the browser window before releasing their button, you won’t get the mouseup event. I’m not sure if there’s anything you can do about that.