6

在 IE11 中使用范围对象 getBoundingClientRect 时,它会报告错误的数字。它报告高度为 128,而实际高度为 74。它报告顶部偏移为 8,而实际顶部偏移为 35。

这是一个已知的错误?有没有办法在 windows ie11 中获得准确的数字选择。

var div = document.querySelectorAll('div')[0];
var t = div.childNodes[0];
var range = document.createRange();
range.setStart(t, 0)
range.setEnd(t, 1)

console.log(range.getBoundingClientRect())
div.text {
  font-size: 64px;
  line-height: 1em;
}
<div class="text">T</div>

这是一个截图供参考:

在此处输入图像描述

4

1 回答 1

2

编辑:

对我来说,Win 7 64bit IE11.0.9600,运行你的代码片段控制台说:

[object ClientRect]{bottom: 72, constructor: ClientRect {...}, height: 64, left: 8, right: 47.090000152...", top: 8, width: 39.090000152..."}

大致匹配 FF 47.0.1 值:

DOMRect { x: 8, y: 3.3333282470703125, width: 38.5, height: 73.33334350585938, top: 3.3333282470703125, right: 46.5, bottom: 76.66667175292969, left: 8 }
于 2016-10-15T02:53:03.170 回答