执行鼠标移动时的鼠标按住事件
我已经下载了一个用于鼠标按住事件的 JQuery 插件。
http://remysharp.com/2006/12/15/jquery-mousehold- event/
我有一个调用 mousemove 事件的 div:
div.addEventListener('mousemove',function() {
//things
});
每当我像这样调用 mousehold 事件时:
var value = 0;
$(div).mousehold(function() {
value += 20;
$(div).html(value);
});
它就会起作用。但是,如果我在 onmousehold 时开始移动(因此调用 mousemove 事件),则该值不再增加,这意味着,即使我的左键单击仍然保持,它也会停止调用 mousehold 事件。
如何才能使鼠标移动时,鼠标按住事件仍然有效?恩克斯!
I've downloaded a JQuery plugin for a mousehold event.
http://remysharp.com/2006/12/15/jquery-mousehold-event/
I have this div that calls for mousemove event:
div.addEventListener('mousemove',function() {
//things
});
whenever I call the mousehold event like this:
var value = 0;
$(div).mousehold(function() {
value += 20;
$(div).html(value);
});
it would work. But if I start moving (thus, calling the mousemove event) while onmousehold, the value does not increase anymore, meaning, it stopped calling the mousehold event even if I got my left click still on hold.
How can I make it happen that when I do a mousemove, the mousehold event still works? tnx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所问的问题(至少我认为您所问的问题)很简单,具有一些基本逻辑。
通过绑定 mousedown、mousemove 和 mouseup 并为鼠标的“按下”状态设置标志,可以轻松完成此操作: JSFiddle
What you're asking (at least, what I think you're asking), is simple enough with some basic logic.
By binding the mousedown, mousemove, and mouseup and setting a flag for the "down" state of the mouse, this can easily be done: JSFiddle
您可以像这样使用事件对象:
You could use the event object like so: