页面向下滚动ajax获取数据的实现方法(兼容手机)
时间:2020-10-24 21:46:18|栏目:JavaScript代码|点击: 次
页面向下滚动ajax获取数据的实现方法(兼容手机)
$(window).scroll(function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = $(this).height(); if (scrollTop + windowHeight >= scrollHeight) { loadPromotions(); } }); var page = 1; var morAvaliable = true;//标识还有数据可以加载 function loadPromotions() { if (morAvaliable) { var href = location.href.split('?')[0]; var pageSize = 5; page++; $.post(href, { pageNo: page, pageSize: pageSize } , function (data) { if (data.length) { var html = ''; $.each(data, function (i, list) { html += '<div class="task-time">' + list.CreateTime + '</div>'; html += '<a class="task-box" href="' + list.Url + '">'; html += '<h5>' + list.Title + '</h5>'; }); $('#promotionList').append(html); } else { morAvaliable = false; $('#loading').html('没有更多分享信息了'); } } ); } }