document.body.getBoundingClientRect().top;当我在一个根本没有样式的简单网站上询问 Firefox 版本 17.0.1时,它返回错误的值。我期望8,这是浏览器的默认设置,但它给了我21.4. 然而,.left偏移量是正确的。
在 Chrome 中,偏移量可以正常工作,并为我8提供了顶部和左侧。
我附上了一个截图,你可以看到顶部不应该是22.4.
这是HTML
<html><head>
<title>Index</title>
<style type="text/css"></style></head>
<body>
    <div>
        <h1>Index</h1>
        <p>This is the index. The site contains in total 4 sites without
            any Javascript. They are linked using href links.</p>
        <p>The site looks like this:</p>
        <ul>
            <li>Index ->; a</li>
            <li>Index ->; b</li>
            <li>b ->; c</li>
            <li>c ->; b</li>
            <li>c ->; Index</li>
        </ul>
    </div>
    <a href="a.html">Go to A</a>
    <a href="b.html">Go to B</a>
</body></html>