I need to detect if a user is scrolled to the bottom of a page. If they are at the bottom of the page, when I add new content to the bottom, I will automatically scroll them
If you're setting height: 100% on some container , then the following code works (tested in Chrome): var wrapper = document.getElementById('wrapper'); wrapper.onscroll = function (evt) { if (wrapper.scrollTop + window.innerHeight >= wrapper.scrollHeight) { console.log('reached bottom!'); } } 0 讨论(0) 查看其它19个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复
height: 100%
, then the following code works (tested in Chrome): var wrapper = document.getElementById('wrapper'); wrapper.onscroll = function (evt) { if (wrapper.scrollTop + window.innerHeight >= wrapper.scrollHeight) { console.log('reached bottom!'); } } 0 讨论(0) 查看其它19个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复
var wrapper = document.getElementById('wrapper'); wrapper.onscroll = function (evt) { if (wrapper.scrollTop + window.innerHeight >= wrapper.scrollHeight) { console.log('reached bottom!'); } }