JQuery Scroll Event Implementation Monitoring scroll bar pagination Simple example

Source: Internet
Author: User

  This article mainly introduces the jquery scroll event Implementation Monitoring scroll bar pagination Simple example, the use of Ajax loading, also introduced (document). Height () and $ (window). Height () the difference, Need friends can refer to the following

The Scroll event applies to the Window object, but it can also scroll through the elements of the IFRAME framework and the CSS overflow property set to scroll.   Code as follows: $ (document). Ready (function () {//I am used to writing     $ (window). Scroll (function () {       //$ (window). ScrollTop () This method is the current scroll bar scrolling distance        //$ (window). Height () Get the height of the current form     & nbsp  //$ (document). Height () get the highest level of the current document         var bot = 50; Bot is the height of the bottom distance         if (bot + $ (window). scrolltop ()) >= ($ (document). Height ()-$ (window). Height ()) {           //when the bottom base distance + scrolling height 〉= The height of the document-the height of the form;            / /We need to load data asynchronously             $.getjson ("url", {page: "2"}, function (str) {alert (str);});        }    }); });   Note: (window). The difference between height () and (document). Height ()   jquery (window). Height () represents the size of the currently visible area, and jquery (document). The height () represents the entire document and can be used in a specific situation.   Note jQuery (window) when the size of the browser window changes (such as maximizing or pulling out the windows). HeIght () changes, but jquery (document). Height () is unchanged.     Code as follows: $ (document). ScrollTop () Gets the distance of vertical scrolling   The distance from the top of the window to the top of the page at the current scrolling location $ (document). ScrollLeft () This is the distance to get the horizontal scroll bar       to get the top only need to get to the scrolltop () ==0   is the top of the   to get the bottom as long as you get ScrollTop () >=$ (document The. Height ()-$ (window). Height ()   You can know that you have scrolled to the end of the   code as follows: $ (document). Height ()  //is the height of the entire page $ (window). Height ()  //is the level of the portion of the page that is currently visible to your browser   This size will change when you zoom the browser window to be different from the document.   should be able to understand according to English.   Just do an experiment. The   code is as follows: $ (document). Scroll (function () {    $ ("#lb"). Text ($ (document). ScrollTop ());) < Span id= "lb" style= "top:100px;left:100px;position:fixed"; ></span><!--a fixed span marker to scroll for easy viewing-->

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.