js移动端的下拉刷新,上拉加载更多。

function refresh(refresh, loadmore) {
    $(window).scroll(function() {
        console.log('正在滑动f');

        //滚动条距离顶部的高度
        var scrollTop = $(this).scrollTop(); 
        //当前页面的总高度
        var scrollHeight = $(document).height(); 
        //当前可视的页面高度
        var clientHeight = $(this).height(); 
        // console.log("top:" + scrollTop + ",doc:" + scrollHeight + ", client:" + clientHeight);

        //距离顶部+当前高度 >=文档总高度 即代表滑动到底部 count++; 
        //每次滑动count加1
        if (scrollTop + clientHeight >= scrollHeight){ 
            //调用筛选方法,count为当前分页数
            // filterData(serviceTypeId, industryId, cityId, count); 

            console.log('下拉');
            if (loadmore) {
                loadmore();
            }
        } else if (scrollTop <= 0) {
            //滚动条距离顶部的高度小于等于0 TODO
            //alert("下拉刷新,要在这调用啥方法?");

            console.log('上拉');
            if (refresh) {
                refresh();
            }
        }
    });
}
var fn1, fn2;
refresh(fn1, fn2);

 

 

 

 

原文:https://www.cnblogs.com/handsomeBoys/p/6557839.html

posted @ 2018-01-01 20:12  烟蓑雨笠卷单行  阅读(617)  评论(0编辑  收藏  举报