开发者

onMouseButtonUp

I need some way to find out when t开发者_运维百科he 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.asp

Or mouseup if 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.


The according event is called onmouseup... You can see a sample implementation here: http://www.webmonkey.com/codelibrary/JavaScript_Event_-_Mouseup


What you might be looking for is something like:

<button onmouseup="alert('hello world');">Say hello world on mouse-up</button>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜