在 VML 和 Internet Explorer 中禁用图形元素选择

发布于 2024-09-09 20:44:12 字数 289 浏览 11 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(2

鲜肉鲜肉永远不皱 2024-09-16 20:44:12

根据所提供的信息很难诊断您的问题。 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.

中性美 2024-09-16 20:44:12

经过一番实验,我找到了部分答案。

goog.events.Event 类具有 PreventDefault 方法。只需处理图形元素上的 MOUSEMOVE 事件即可。然后调用 event#preventDefault 方法:

var element = ... // some element
var graphics = goog.graphics.createGraphics('400', '300');

var fill = new goog.graphics.SolidFill('#00ff00', 0.5);
var stroke = new goog.graphics.Stroke(1, 'black');

graphics.drawEllipse(60, 60, 10, 10, stroke, fill);
graphics.drawEllipse(90, 90, 10, 10, stroke, fill);

graphics.render(element);

goog.events.listen(graphics.getElement(), goog.events.EventType.MOUSEMOVE, function(e) {
  e.preventDefault();
  e.stopPropagation();
});

在图形元素内部单击,然后拖动不再选择圆圈。同样,这仅在 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:

var element = ... // some element
var graphics = goog.graphics.createGraphics('400', '300');

var fill = new goog.graphics.SolidFill('#00ff00', 0.5);
var stroke = new goog.graphics.Stroke(1, 'black');

graphics.drawEllipse(60, 60, 10, 10, stroke, fill);
graphics.drawEllipse(90, 90, 10, 10, stroke, fill);

graphics.render(element);

goog.events.listen(graphics.getElement(), goog.events.EventType.MOUSEMOVE, function(e) {
  e.preventDefault();
  e.stopPropagation();
});

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文