简体   繁体   English

检查用户是否滚动到页面底部的跨浏览器方式是什么?

[英]what is the cross browser way to check if user scrolled to bottom of page?

i'm trying to load more results when user scroll to the bottom of page.当用户滚动到页面底部时,我试图加载更多结果。 i want it to be as much as possible cross browser(dose not matter if it's jquery or js) it should support ie8 at least!我希望它尽可能地跨浏览器(不管它是 jquery 还是 js)它至少应该支持 ie8! right now for checking if user have scrolled to the bottom of page i use this code:现在检查用户是否已滚动到页面底部,我使用以下代码:

var sTop = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;
if(sTop + window.outerHeight == document.body.clientHeight)  //user scrolled to bottom of the page?

but it's not cross browser.但它不是跨浏览器。

var currentBottom = $(window).scrollTop() + $(window).height();
var bodyHeight = $('body').height();
if (currentBottom >= bodyHeight) {
  console.log("Reached bottom");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM