DOM尺寸

浏览器尺寸的兼容性
一、浏览器兼容模式
怪异模式和标准模式
BackCompat CSS1Compat
二、浏览器窗口可视区域尺寸
IE8及以下:
标准:document.documentElement.clientWidth/clientHeight;
怪异:document.body.clientWidth/clientHeight;
获取可视区域大小:
1 | function getViewportSize() { |
三.滚动条距离

获取滚动条距离(兼容性处理):
1 | function getScrollOffset() { |
四、文档尺寸
文档的真实大小,包括不可见部分。
1 | function getScrollSize() { |
五、盒子外边距
相对边距
1、offsetTop/offsetLeft:相对于定位的祖先元素的上/左边距离,如果没有定位的祖先元素,则为距离浏览器窗口的边距;
2、offsetParent:获取该元素最近的有定位的祖先元素,如果没有找到定位的祖先元素,则为body元素;
绝对边距
获取盒子距离浏览器左/上的距离。
1 | function getElemDocPosition(el) { |
六、操控滚动条
window.scroll(x, y)
window.scrollTo(x, y)
window.scrollBy(x, y)
- Post title: DOM尺寸
- Create time: 2021-01-23 13:15:00
- Post link: 2021/01/23/DOM尺寸/
- Copyright notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.
Comments