鼠标按钮向上

发布于 2024-08-18 18:39:44 字数 213 浏览 3 评论 0原文

我需要某种方法来找出用户何时释放鼠标按钮 - 类似 keyUp - 但对于鼠标......

有什么想法吗?

PS:我想模仿:活动伪类,我的想法是在鼠标按下做某事(),并在UnDoSomething()鼠标按钮向上 ...现在...如果您有更好的解决方案 - 来找我吧! :)

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! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

春风十里 2024-08-25 18:39:44

该事件是 onmouseuphttp://www.w3schools.com/ jsref/event_onmouseup.asp

mouseup(如果您正在调用 element.addEventListener 或使用删除名称中“on”部分的 JavaScript 框架之一)。

更新:

如果您想监听任何鼠标松开事件,您需要在 onmousedown 回调中的页面主体上注册一个 onmouseup 监听器,然后取消注册 onmouseup来自 onmouseup 回调的侦听器(因此它只发生一次)。

如果您使用的是 jQuery,则可以使用 one() 函数来完成此操作。

当然,如果用户在释放按钮之前将鼠标移到浏览器窗口之外,您将不会收到 mouseup 事件。我不确定你是否能对此做些什么。

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.

最丧也最甜 2024-08-25 18:39:44

相应的事件称为 onmouseup...您可以在此处查看示例实现:
http://www.webmonkey.com/codelibrary/JavaScript_Event_-_Mouseup

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

送君千里 2024-08-25 18:39:44

您可能正在寻找类似的内容:

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

What you might be looking for is something like:

<button onmouseup="alert('hello world');">Say hello world on mouse-up</button>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文