美文网首页
js获取元素的宽高

js获取元素的宽高

作者: 时间de歌 | 来源:发表于2017-10-17 18:05 被阅读4次
  • dom.style.width/height:只能获取内联样式的宽和高
  • dom.currentStyle.width/height:仅IE支持。
  • window.getComputedStyle(dom, 伪类).width/height: IE<9不支持该属性。
    window.getComputedStyle(dom, 伪类)返回一个只读的CSSStyleDeclaration对象,通过getPropertyValue()获取
  • dom.getBoundingClientRect():返回一个````DOMReact对象,除了width,height属性属性,top,left,right,bottom都是相对于视口的 在IE<9的浏览器返回的DOMRect对象没有width,height```

参考

相关文章

网友评论

      本文标题:js获取元素的宽高

      本文链接:https://www.haomeiwen.com/subject/yiiluxtx.html