💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
## 彻底搞懂 clientHeight、offsetHeight、scrollHeight、scrollTop、offsetTop 1. clientHeight 和 clientWidth clientHeight 代表元素的高度,和滚动没有关系 ![](https://img.kancloud.cn/d3/5d/d35d2d1d46c6e59d66733edca7bb9cac_1760x921.png) 2. offsetHeiht 和 offsetWidth 包括内容的高度 + padding + border + 水平滚动条 ![](https://img.kancloud.cn/9f/94/9f941f768a1f58b41c90a4194a58cd82_1827x893.png) 3. scrollHeight 只有在出现滚动条的时候,才需要讨论 scrollHeight 没有滚动条时, scrollHeight == clientHeight ![](https://img.kancloud.cn/a3/bc/a3bc142ab03fa4e2db4d3d7a12467069_511x413.png) 判断元素是否滚动到底部 ``` scrollHeight - scrollTop == clientHeight ``` ![](https://img.kancloud.cn/e0/67/e067893ba1314f5d3f71d741fe866582_949x569.png) 4. scrollTop 在有滚动条时,scrollTop 为元素被卷上去的高度 ![](https://img.kancloud.cn/e5/34/e5344bd59ae22de645c3f309e0b1b338_511x413.png) 5. offsetTop 与滚动没有关系,是当前元素离最近父元素顶部的距离 ![](https://img.kancloud.cn/93/92/9392098e1e6fd11c333143ef36ba0d3f_647x493.png)