
clientWidth-offsetHeight
clientWidth
clientWidth 属性是一个只读属性,它返回该元素的像素宽度,宽度包含内边距(padding),不包含边框(border),外边距(margin)和滚动条,是一个整数,单位是像素 px。
内联元素以及没有 CSS 样式的元素的 clientWidth 属性值为 0。
获取浏览器窗口宽高:
1 2 3 4 5 6 7 8 9 10
| const screenWidth = document.documentElement.clientWidth || document.body.clientWidth; const screenHeight = document.documentElement.clientHeight || document.body.clientHeight;
const screenWidth = window.screen.width; const screenHeight = window.screen.height;
const screenWidth = window.screen.width * window.devicePixelRatio; const screenHeight = window.screen.height * window.devicePixelRatio;
|
![image-20230811211224296]()
offsetHeight
offsetHeight 和 offsettWidth 属性返回元素的可见高度和宽度,包括内边距(padding)和边框(border)。
![image-20230811211230479]()