Judging the scroll bar to the bottom, you need to use the DOM's three attribute values, namely ScrollTop, ClientHeight, ScrollHeight. scrolltop is the scroll distance of the scrollbar on the y-axis. clientheight is the height of the viewable area of the content. scrollheight the height of the viewable area of the content plus the distance to overflow (scroll). From this three properties of the introduction can be seen, scroll bar to the bottom of the condition is scrolltop + clientheight = = ScrollHeight. The code is as follows (compatible with different browsers). //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;} The total height of the //document is 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;} //the height of the browser viewport 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 ("already to the bottom!!"); }}; is easier if it is implemented with jquery, $ (window). Scroll (function () {var scrolltop = $ (this). ScrollTop (); var scrollheight = $ (document). Height (); var WindowHeight = $ (this). Height (); if (scrolltop + windowheight = = scrollheight) {alert ("already to the bottom!") "); }}); if you want to determine whether the scroll bars in an element are in the bottom, according to similar ideas, Change the document.body to a specific element, get scrolltop and scrollheight the same way, but get the element visible height need to use the offsetheight attribute, directly according to gourd painting scoop.
JS How to determine if the scroll bar is rolled to the bottom