js获取元素的宽高和页面的宽高

86 阅读1分钟

var dom = document.getElementById('div')

  • offset方法获取

  • dom.offsetWidth

  • dom.offsetHight

  • 元素的宽度包含padding与border

  • client方法获取

  • dom.clientWidht

  • dom.clientHight

  • 元素的宽度不包含padding与border

  • Window.getComputedStyle(dom).width

  • 元素的宽度不包含padding与border

  • js获取页面的宽高

  • document.documentElement.scrollWidth

  • document.documentElement.scrollHight