JQuery to determine the scroll bar to the bottom, jquery scroll bar

Source: Internet
Author: User

JQuery to determine the scroll bar to the bottom, jquery scroll bar

To judge the scroll bar to the bottom, three DOM attribute values are required, namely 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

<!doctype html>

The above is all the content of this article. I hope you will like it.

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.