JS for unlimited load paging (for mobile)

Source: Internet
Author: User

principle: When the scroll bar reaches the bottom, the next page of content is executed.

Judging conditions requires understanding three concepts:
1.scrollHeight the height of real content
Height of the 2.clientHeight window, which is the height of the content you can see in the browser
The hidden portion of the 3.scrollTop window, that is, the distance the scroll bar scrolls

Ideas:
1. Using the Fixed position loading box
2. Use the $ (window). Scroll () method to trigger whether to load

3. Through the real content height-window height-Hidden parts < 5, as the conditions for loading trigger

JavaScript code:

<script type= "Text/javascript" > var page=2; Current page number Var allpage;    The total page number, will get the Var catid= "{$catid}" from the background; function Showajax (page) {$.ajax ({URL: "", type: "Post", Data:{page:page,catid              : CatID}, success:function (data) {//content to be executed showcontent (data); }})} function Scrollfn () {//the height of the real content var pageheight = Math.max (document.body.scrollheight,docu        Ment.body.offsetHeight); The height of the window var viewportheight = window.innerheight | | Document.documentElement.clientHeight | | Document.body.clientHeight | |        0; Hidden height var scrollheight = Window.pageyoffset | | Document.documentElement.scrollTop | | Document.body.scrollTop | |        0;        if (Pageheight-viewportheight-scrollheight < 50) {//If the trigger condition is met, execute Showajax (page);      }} function Showcontent (data) {var list=eval (' (' +data+ ') ');      var ss= '; for (var i in list) {       ss=ss+ ' <li><a href= "' +list[i][' url ']+ '" > ' +list[i][' title ']+ ' </a></li> ';      } $ (". Minsulist"). Append (ss);  page++; Number of pages plus 1} $ (window). Bind ("scroll", SCROLLFN);//bound scrolling event </script>

  

Two

$ (window). Scroll (function () {
has scrolled to the top of the page height
var scrolltop = $ (this). ScrollTop ();
Page height
var scrollheight = $ (document). Height ();
browser window height
var WindowHeight = $ (this). Height ();
Here is the event triggered by the scroll bar to the bottom, where the data to be loaded is written, or the action that pulls the scroll bar
if (scrolltop + windowheight = = scrollheight) {
Dragthis.insertdom ();
}
});

Third, JS plug-in

Mobile drop-down refresh, pull-up load more plugins droploadH5 based on iscroll implementation pull-down refresh, pull-up load more

JS for unlimited load paging (for mobile)

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.