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.