Implementation of web scrolling paging on mobile terminals, and web scrolling paging on mobile terminals

Source: Internet
Author: User

Implementation of web scrolling paging on mobile terminals, and web scrolling paging on mobile terminals

The examples in this article share with you the code for displaying mobile web scrolling pages for your reference. The details are as follows:

Method 1:Front-end code:

<Script type = "text/javascript"> var page = 2; // the current page number var flagNoData = false; // false var allpage = @ Model. pageCount; // The total page number. function showAjax (currentIndex) {$. ajax ({url: "@ Url. action ("GetEmployeeData", "Home") ", type:" GET ", data: {" pageNum ": currentIndex}, success: function (data) {// showContent (data); if (currentIndex> = allpage) {// the current page number is greater than or equal to the total page number flagNoData = true ;}; page + = 1; // page number plus 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 (flagNoData) {// return;} else if (pageHeight-viewportHeight-scrollHeight <10) {// if the trigger condition is met, execute showAjax (page) ;}$ (window ). bind ("scroll", scrollFn); // bind the rolling event function showContent (datacontent) {$ ("# contentDiv "). append (datacontent) ;}</script>

Applicable to pull-down and scroll pages on mobile and PC pages

Method 2 (recommended ):

Plugin https://github.com/ximan/dropload

Download the plug-in and reference css and js:

<link rel="stylesheet" href="~/Content/dropload.css" rel="external nofollow" /><script type="text/javascript" src="~/Scripts/dropload.min.js"></script>
@section scripts{  <script type="text/javascript" src="~/Scripts/dropload.min.js"></script>  <script type="text/javascript">    $(function () {      var page = 1;      var pageSize = 10;      $(".content").dropload({        scrollArea: window,        loadDownFn: function (me) {          page++;          var result = '';          $.ajax({            url: "@Url.Action("GetEmployeeData", "Home")",            type: "GET",            data: { "pageNum": page },            success: function (data) {              var arrlen = data.length;              if (arrlen > 0) {                showContent(data);                me.resetload();              } else {                me.lock();                me.noData();              }            },            error: function (xhr, type) {              alert('Ajax error:' + xhr + type);              me.resetload();            }          })        }      })    });    function showContent(datacontent) {      $("#contentDiv").append(datacontent);    }  </script>  }

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.