移动端下拉ajax加载分页 (1049 views)

tofu

2017-02-13 11:34:52

 <script type="text/javascript">
$(function () {
var docHeight = $(document).height();
var windowHeight = $(window).innerHeight();
var beforScrollHeight = 0;
var afterScrollHeight = 0;
var list_box = $("#list_box");

var nextPage = {$nextPage};

$(window).scroll(function () {
//记录上一次滚动的位置
afterScrollHeight = $(document).scrollTop();
docHeight = $(document).height();
//当下滚才更新

if (nextPage) {
if (beforScrollHeight < afterScrollHeight) {
if (afterScrollHeight + windowHeight == docHeight) {
beforScrollHeight = afterScrollHeight;
$.post(
"{:U('/userflow/ajaxGetCi')}",
{p: nextPage},
function (result) {
list_box.append(result.htmlcode);
nextPage = result.nextPage;
}, 'json');
}
}
}
});
});
</script>