Sample Code sharing for unlimited page loading on Mobile Terminals Based on JavaScript

Source: Internet
Author: User
This article mainly introduces how to implement unlimited page loading on Mobile Terminals Based on JavaScript, which has some reference value, if you are interested, please refer to this article to introduce in detail how to implement unlimited page loading on Mobile Terminals Based on JavaScript, which has some reference value. If you are interested, please refer

The examples in this article share with you the specific code for js to implement unlimited page loading on mobile terminals for your reference. The specific content is as follows:

Principle:When the scroll bar reaches the bottom, execute the next page.

The judgment condition must be understood in three concepts:
1. scrollHeight the height of the actual content
2. The height of the clientHeight window, that is, the height of the content that can be seen in the browser
3. the hidden part of the scrollTop window, that is, the scroll distance of the scroll bar.

Ideas:

1. Use fixed to locate the loading box
2. Use the $ (window). scroll (); Method to trigger loading.
3. Use the actual content height-window height-hidden part above <10 as the loading trigger condition.

Sample Code

Var page = 1; // the current page number var flagNoData = false; // false var allpage; // The total page number, which will be retrieved from the background by function showAjax (page) {$. ajax ({url: "", type: "", data: "", success: function (data) {// showContent (); if (page> = data. allpage) {// the current page number is greater than or equal to the total page number. flagNoData = true ;}; page ++ = 1; // the page number is added to 1 })} function scrollFn () {// The height of the actual content var pageHeight = Math. max (document. body. scrollHeight, document. body. offsetHeight); // The height of the window var viewportHeight = window. innerHeight | document.doc umentElement. clientHeight | document. body. clientHeight | 0; // The Hidden height var scrollHeight = window. pageYOffset | document.doc umentElement. scrollTop | document. body. scrollTop | 0; if (falgNoData) {// return;} else if (pageHeight-viewportHeight-scrollHeight <10) {// if the trigger condition is met, execute showAjax (page) ;}$ (window ). bind ("scroll", scrollFn); // bind a rolling event

The above is the sample code sharing for unlimited page loading on Mobile Terminals Based on JavaScript. For more information, see other related articles in the first PHP community!

Related Article

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.