这个问题以前有人问过关于“高度”和“宽度”属性,但我没有找到有效的解决办法。
在火狐中,值
auto的属性返回使用的值,而不是值auto。
但是,window.getComputedStyle(element).getPropertyValue("top")返回的是"auto"而不是像素值。有人知道解决办法吗?
Ubuntu 15.04上的Firefox 42.0
发布于 2015-11-12 19:10:50
看起来您的元素有position: static。任何其他类型的定位似乎都是正确计算的。下面是一个静态元素的测试:
document.getElementById('results').innerHTML = window.getComputedStyle(document.getElementById('element')).top;#element {
top : auto;
}<div id="element"></div>
<pre id="results"></pre>
这是position: relative的另一张
document.getElementById('results').innerHTML = window.getComputedStyle(document.getElementById('element')).top;#element {
position: relative;
top : auto;
}<div id="element"></div>
<pre id="results"></pre>
top应该是static元素的no操作。因此,在这种情况下,最好使用Rect方法。
https://stackoverflow.com/questions/33678641
复制相似问题