js获取元素的宽高

  • 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```

参考

  • getComputedStyle

你可能感兴趣的:(js获取元素的宽高)