在 VML 和 Internet Explorer 中禁用图形元素选择
我有一个 JavaScript 应用程序,可以让用户在绘图区域周围移动形状,并且我碰巧正在使用 Google Closure 库。在 FF/Safari 中一切都很好。在 IE 中,当图形元素移动时,它们会被浏览器选中(移动元素和其他元素),以不可预测的方式在某些元素周围显示彩色虚线背景:
https://i.sstatic.net/JRIh1.png
如何在 IE 中关闭此行为?
I have a JavaScript application that lets users move shapes around a drawing area, and I happen to be using the Google Closure library. In FF/Safari all is good. In IE, as graphic elements are moved, they get selected by the browser (both the moving element and other elements), showing colored dotted background around some elements in unpredictable ways:
https://i.sstatic.net/JRIh1.png
How can I turn off this behavior in IE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据所提供的信息很难诊断您的问题。 IE VML 没有得到很好的支持,因此有很多错误。
在DojoX Drawing中,我在绘制线条时遇到了类似的问题。 VML 有一个错误,您无法同时拖动和调整大小 - 但是,您可以同时拖动和创建,因此我重新绘制了线条,而不对其进行变换。
此外,我不会将单击/拖动事件附加到形状,而是将它们附加到整个主容器,检测 mousedown 事件上的 id,然后跟踪 mousemove 并通过在形状容器上执行 setTransform 来移动形状。
本质上,由于 VML 支持较弱,您必须愿意尝试完全不同的事情才能使其正常工作。
It's hard to diagnose your problem on the information provided. IE VML is not very well supported and therefore pretty buggy.
In DojoX Drawing, I ran into a similar problem when drawing lines. VML has a bug where you can't drag and resize at the same time – but, you can drag and create at the same time, so I redraw the line, I don't transform it.
Further, I don't attach my click/drag events to the shape, I attach them to the overall main container, detect the id on the mousedown event, then track the mousemove and move the shape via doing a setTransform on the shape's container.
Essentially, because of the weak VML support, you have to be willing to try totally different things to get it to work.
经过一番实验,我找到了部分答案。
goog.events.Event 类具有 PreventDefault 方法。只需处理图形元素上的 MOUSEMOVE 事件即可。然后调用 event#preventDefault 方法:
在图形元素内部单击,然后拖动不再选择圆圈。同样,这仅在 IE 上是必需的。
仍然存在一个小问题。在图形区域外按鼠标,然后将光标拖动到图形区域中,则会选择整个区域,或同时选择区域和图形元素。
After some experimentation, I found a partial answer.
The goog.events.Event class has a preventDefault method. Simply handle the MOUSEMOVE event on the graphics' element. Then call the event#preventDefault method:
Clicking inside the graphics element, then dragging no longer selects the circles. Again, this is only necessary on IE.
One minor problem remains. Pressing the mouse outside of the graphics area, then dragging the cursor into the graphics area results in the entire area being selected, or both the area and graphical elements.