【问题标题】:Next code runs in FireFox and Chrome. What's the error when when I run it in IE?下一个代码在 FireFox 和 Chrome 中运行。当我在IE中运行它时出现什么错误?
【发布时间】:2018-01-21 18:26:37
【问题描述】:

我正在尝试获取一个元素弹跳框,如下所示:

var bboxRealDibujo = gRootDibujo.getBoundingClientRect();           //El bbox del dibujo.
    var bboxRealVentanaDeZoom = ventanaDeZoom.getBoundingClientRect();  //El bbox de la ventana de zoom.

    console.log ("Lienzo XY: "+bboxRealDibujo.left+", "+bboxRealDibujo.top+"     /     Lienzo WH "+ bboxRealDibujo.width+", "+bboxRealDibujo.height);
    console.log ("Ventana Zoom XY:"+bboxRealVentanaDeZoom.left+", "+bboxRealVentanaDeZoom.top+"     /     Lienzo WH"+ bboxRealVentanaDeZoom.width+", "+bboxRealVentanaDeZoom.height);

正如您在附图中看到的那样,我在 Firefox / chrome 中没有任何问题,但在 IE 中,变量 x,y 返回为“未定义”(也尝试使用左、上、相同的结果)。

问题是:是类型命令错误,还是IE有自己的命令(和往常一样)?

提前致谢。

enter image description here

【问题讨论】:

    标签: javascript internet-explorer svg


    【解决方案1】:

    根据MDN,IE支持getBoundingClientRect,但不支持xy属性。

    IE 和 Edge 返回一个 (ClientRectList with) MSDN:不包含 x 和 y 属性的 ClientRect 对象,而不是 DOMRect 对象

    另一种方法是分别使用rect.leftrect.top 而不是xy

    【讨论】:

      猜你喜欢
      • 2023-01-05
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 2012-10-17
      • 1970-01-01
      • 2019-01-26
      • 2016-04-15
      • 1970-01-01
      相关资源
      最近更新 更多