js上拉刷新数据

    $(window).scroll(function () {

        //下面这句主要是获取网页的总高度,主要是考虑兼容性所以把Ie支持的documentElement也写了,这个方法至少支持IE8
        var htmlHeight = $(document).height();
        //clientHeight是网页在浏览器中的可视高度,
        var clientHeight = $(window).height();
        //scrollTop滚动条到顶部的垂直高度
        var scrollTop = $(window).scrollTop();
        //通过判断滚动条的top位置与可视网页之和与整个网页的高度是否相等来决定是否加载内容;
        var he = scrollTop + clientHeight;
        if (he >= htmlHeight * 0.9 && gettype == 1) {
            page = page + 1
            getNewData(level, key, page)//此处是调用请求方法
            gettype = 0
        }
    });
gettype 初始化
let times_over = () => {
    setTimeout(function () {
        gettype = 1
        console.log(gettype)
    }, 500);
}

 

posted @ 2020-03-26 12:01  一半人生  阅读(500)  评论(0编辑  收藏  举报