如何使拖动检测更加稳健
我将全局“单击”状态存储在变量中,以便检测拖动,或者检测将鼠标悬停在元素上时是否按住鼠标。
问题是,即使释放鼠标按钮,各种情况也可能导致“已单击”状态保持“true”状态,例如弹出警报。
有解决办法吗?
编辑:
我开始认为“各种事情”可能仅限于警报,并且浏览器由于按下键盘快捷键等原因而失去焦点。我想这可以忍受。
I'm storing a global "clicked" status in a variable in order to detect dragging, or to detect if the mouse is being held down while mousing into an element.
The problem is that various things can cause the "clicked" status to remain true
even when the mouse button is release, for example if an alert pops up.
Is there a solution?
Edit:
I'm coming to think that "various things" may be limited to alerts, and the browser losing focus due to something like a keyboard shortcut being pressed. I suppose this can be lived with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的!点击状态不可信...
这让我沮丧了好几个小时。
但也许 JQuery Draggable 仍然是您的解决方案。
您需要做的就是使用透明助手:
更多信息请参见: http://jqueryui.com/ demos/draggable/#event-start(自定义帮助器示例)
作为辅助,您可以将 droppable 与悬停类一起使用:
http://jqueryui.com/demos /droppable/#视觉反馈
You are right! the click status cannot be trusted...
it frustrated me for hours.
but maybe JQuery draggable is still a solution for you.
All you need to do is use a transparent helper:
more at: http://jqueryui.com/demos/draggable/#event-start (the custom helper example)
As a side-kick you can use droppable with hover class:
http://jqueryui.com/demos/droppable/#visual-feedback