This article mainly introduces jQuery's implementation of the relevant information to determine the scroll bar to the bottom. If you need a friend, you can refer to the following to determine the scroll bar to the bottom. You need to use the DOM's three attribute values, that is, scrollTop, clientHeight, and scrollHeight.
ScrollTop indicates the scroll distance of the scroll bar on the Y axis.
ClientHeight is the height of the visible area of the content.
ScrollHeight is the height of the visible area of the content plus the overflow (scroll) distance.
From the introduction of these three attributes, we can see that the condition from the scroll bar to the bottom is scrollTop + clientHeight = scrollHeight.
Get started with code (compatible with different browsers ).
Lazyload. js
Scroll // The scroll distance of the scroll bar on the Y axis function getScrollTop () {var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0; if (document. body) {bodyScrollTop = document. body. scrollTop;} if(document.doc umentElement) {documentScrollTop = document.doc umentElement. scrollTop;} scrollTop = (bodyScrollTop-documentScrollTop> 0 )? BodyScrollTop: documentScrollTop; return scrollTop;} // function getScrollHeight () {var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0; if (document. body) {bodyScrollHeight = document. body. scrollHeight;} if(document.doc umentElement) {documentScrollHeight = document.doc umentElement. scrollHeight;} scrollHeight = (bodyScrollHeight-documentScrollHeight> 0 )? BodyScrollHeight: documentScrollHeight; return scrollHeight;} // function getmediawheight () {var transport wheight = 0; if (document. compatMode = "CSS1Compat") {export wheight = document.doc umentElement. clientHeight;} else {transport wheight = document. body. clientHeight;} return previous wheight;} window. onscroll = function () {if (getScrollTop () + getWindowHeight () = getScrollHeight () {alert ("you are I N the bottom! ");}};
Lazyload-jQuery.js
$(window).scroll(function(){ var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = $(this).height(); if(scrollTop + windowHeight == scrollHeight){ alert("you are in the bottom"); }});
LazyLoad.html