• 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);
    
  • 相关阅读:
    使用CAShapeLayer做出圆形的进度条 —— #DF!
    NSDate分类,把系统返回的时间与现在进行比较---秀清
    NSPredicate类,指定过滤器的条件---董鑫
    UITextFIeld的输入格式问题 ----W.P
    AttributeText创建多彩文字Label --- hl
    自定义简单动画
    Swift 学习网址精选 By HL
    【C++服务端技术】移动广播
    【C++服务端技术】定时器
    【面试攻略】C++面试-4399
  • 原文地址:https://www.cnblogs.com/Byme/p/8527922.html
Copyright © 2020-2023  润新知