scrollTop 和 scrollHeight的意思

本文介绍了如何使用div.scrollTop=div.scrollHeight的方法实现对话框始终保持在页面底部的实时更新效果。通过解释scrollTop和scrollHeight两个属性的区别及作用,帮助读者理解其实现原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天要用到实时显示最近更新内容,也就是要让对话框随时都在最底部。

查了一下,

用div.scrollTop=div.scrollHeight;就可以了。

又查了查这两个参数什么意思。stackoverflow上面有人是这样解答的。


If I scroll down 5px in this window, the window's scrollTop value is 5. If I scroll right 10px in a scrollable div, the div's scrollLeft value is 10.

When I scroll to the top left corner of this window, both its scrollTop and scrollLeft values are 0.

还有一个人作了补充: scrollTop and scrollHeight. In summary, scrollTop is how much it's currently scrolled, and scrollHeight is the total height, including content scrolled out of view.

总的来说,scrollTop就是卷起来的部分,也就是我们随着下拉,看不见的部分。scrollHeight就是整个窗口可以滑动的高度。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值