js——滚动加载

 

            $(function () {
            //滚动加载
            var n = 2;
            var total = "<%=TotalPage %>";
            $(window).scroll(function () {
                var scrolltop = $(window).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(window).height();
                if (scrolltop >= scrollHeight - windowHeight) {
                    $("#loading").css("display", "block");
                    if (n <= total) {
                        $.ajax({
                            url: "Xmlhttp/GameList.aspx?ope=4&hot=1&index=" + n,
                            async: false,
                            cache: false,
                            success: function (data) {
                                if (data.split('|').length == 2) {
                                    $("#loading").before(data.split('|')[1]);
                                    $("#loading").css("display", "none");
                                    n++;
                                }
                            },
                            error: function () {
                                console.log("请求失败");
                            }
                        })
                    }
                    else {
                        $("#loading").css("display", "none");
                        $("#all").css("display", "block");
                    }
                }
            }
            );
        })

 

posted on 2017-08-03 17:10  奔游浪子  阅读(96)  评论(0)    收藏  举报

导航