js 移动端上拉刷新(基于ng1)
//分页下拉 var ajaxScroll = function() { var screenHeight = window.screen.height; $(document).scroll(function() { if (screenHeight + document.body.scrollTop >= document.body.scrollHeight) { $scope.pageNum = Math.ceil($scope.total / $scope.pageSize); if ($scope.pageNo <= $scope.pageNum) { $scope.pageNo++; $scope.tips = '正在加载数据...'; setTimeout(function() { loadData($scope.state, $scope.pageNo); }, 500); $scope.$apply(); } $(document).unbind('scroll'); } }) }
$scope.pageNo = 1; //第几页 $scope.pageSize = 5; //展示条数 $scope.total; //总条数 $scope.tasks = []; $scope.state = 0; //加载列表 function loadData(state, page) { $.ajax({ type: "get", url: webroot + '/services/api/task/list/' + state + '?' + 'pageNo=' + $scope.pageNo + '&pageSize=' + $scope.pageSize, dataType: "json", headers: { 'ticket': ticket }, success: function(rsp) { if (rsp.code == 200) { $scope.total = rsp.result.total; // $scope.tasks = rsp.result.tasks; if ($scope.tasks) { for (var i = 0; i < rsp.result.tasks.length; i++) { $scope.tasks.push(rsp.result.tasks[i]); } } else { $scope.tasks = rsp.result.tasks; } if ($scope.pageNo >= (Math.ceil($scope.total / $scope.pageSize)) && rsp.result.tasks.length) { $scope.tips = '已经全部加载完毕'; } else if (!rsp.result.tasks.length) { $scope.tips = '暂时没有数据'; } else { ajaxScroll(); } $scope.pageNo = rsp.result.pageNo; $scope.$apply(); } else { console.log(rsp.message) } }, error: function(data) { console.log("error"); }, }); }; //首次加载 loadData($scope.state, $scope.pageNo);