Determine whether the scroll bar has reached the bottom

Source: Internet
Author: User
1 // retrieve the scroll bar height of the window
2 function getscrolltop (){
3 var scrolltop = 0;
4 If (document.doc umentelement & document.doc umentelement. scrolltop ){
5 scrolltop = document.doc umentelement. scrolltop;
6}
7 else if (document. Body ){
8 scrolltop = Document. Body. scrolltop;
9}
10 return scrolltop;
11}
12
13
14 // take the height of the visible window range
15 function getclientheight (){
16 var clientheight = 0;
17 if (document. Body. clientheight & document.doc umentelement. clientheight ){
18 var clientheight = (document. Body. clientheight <document.doc umentelement. clientheight )? Document. Body. clientheight: document.doc umentelement. clientheight;
19}
20 else {
21 var clientheight = (document. Body. clientheight> document.doc umentelement. clientheight )? Document. Body. clientheight: document.doc umentelement. clientheight;
22}
23 return clientheight;
24}
25
26 // take the actual height of the Document Content
27 function getscrollheight (){
28 return math. Max (document. Body. scrollheight, document.doc umentelement. scrollheight );
29}

Conditions for the scroll bar to reach the bottom: getscrolltop () + getclientheight () = getscrollheight ()

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.