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!