To determine the scroll bar to the bottom, you need to use the DOM's three property values, namely ScrollTop, ClientHeight, ScrollHeight.
ScrollTop is the scroll distance of the scroll bar on the y-axis.
ClientHeight is the height of the content viewable area.
ScrollHeight adds an overflow (scrolling) distance to the height of the content viewable area.
From the introduction of this three attributes can be seen, the scroll bar to the bottom of the condition is scrolltop + clientheight = = ScrollHeight.
Nonsense not much said, hurriedly on the code (compatible with different browsers).
Lazyload.js
Scroll bar on the y-axis of the scrolling distance function getscrolltop () {var scrolltop = 0, bodyscrolltop = 0, documentscrolltop = 0;
if (document.body) {bodyscrolltop = Document.body.scrollTop;
} if (document.documentelement) {documentscrolltop = Document.documentElement.scrollTop; } scrolltop = (bodyscrolltop-documentscrolltop > 0)?
Bodyscrolltop:documentscrolltop;
return scrolltop;
}//Document's total height function getscrollheight () {var scrollheight = 0, bodyscrollheight = 0, documentscrollheight = 0;
if (document.body) {bodyscrollheight = Document.body.scrollHeight;
} if (document.documentelement) {documentscrollheight = Document.documentElement.scrollHeight; } scrollheight = (bodyscrollheight-documentscrollheight > 0)?
Bodyscrollheight:documentscrollheight;
return scrollheight;
}//Browser viewport's height function getwindowheight () {var windowheight = 0;
if (Document.compatmode = = "Css1compat") {windowheight = Document.documentElement.clientHeight; }else{WindOwheight = Document.body.clientHeight;
return windowheight; } Window.onscroll = function () {if (Getscrolltop () + getwindowheight () = = Getscrollheight ()) {alert ("You are in 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
The above is the entire contents of this article, I hope you can enjoy.