用js获取元素定位,发现chrome下,忽略了元素offsetHeight。其他浏览器可以根据子元素的样式计算出父级的高度,盒模型。而chrome则不可以、得为其元素设置高度,才能再通过js获取到offsetHeight。

firfox:

chrome offsetHeight|clientHeight

chrome:

chrome offsetHeight|clientHeight

设置height由于元素<span>为行内元素,还得添加display:block。

chrome:

chrome offsetHeight|clientHeight

 

另外一个点,offsetHeight|clientHeight的区别:

  offsetHeight包含height、padding、scrollBar、border。

  clientHeight包含height、padding。

  http://help.dottoro.com/ljuxqbfx.php

The offsetHeight returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.
The clientHeight property is similar to the offsetHeight property, but it returns the height including only the padding.

相关文章:

  • 2021-09-12
  • 2021-11-21
  • 2021-11-21
  • 2021-04-13
  • 2021-09-29
  • 2021-05-06
猜你喜欢
  • 2021-11-21
  • 2021-10-29
  • 2022-03-07
  • 2021-11-21
  • 2021-10-07
  • 2021-09-08
  • 2021-12-20
相关资源
相似解决方案