zoukankan      html  css  js  c++  java
  • 懒加载数据


    // 滚动加载数据
    var g_datas_index = 1 // 业务代码 可忽略
    $(window).scroll(function(){
    var scrollTop = $(this).scrollTop()
    var scrollHeight = $(document).height()
    var windowHeight = $(this).height()
    if(scrollTop + windowHeight == scrollHeight){ // 相等代表已滚动到底
    // 下面执行到底后想要执行的操作
    g_datas_index = g_datas_index + 1
    processContent(unionid, up_list, g_datas_index)
    }
    })




    // 滚动加载数据 滚动条的一半就加载数据,向上滑动不加载数据
    var g_datas_index = 1;
    var g_lazy_status = 0;
    var g_top = 0;
    $(window).scroll(function(){
    var scrollTop = $(this).scrollTop();
    var scrollHeight = $(document).height();
    var windowHeight = $(this).height();

    if(scrollTop + windowHeight >= scrollHeight / 2 && g_lazy_status == 0 && scrollTop > g_top){
    // 记录本次高度
    g_top = scrollTop;
    // 修改状态,为 1 时不加载数据
    g_lazy_status = 1;
    g_datas_index = g_datas_index + 1;
    console.log(g_datas_index);
    lazy_loading(g_datas_index);
    }
    });
    // lazy_loading 函数里需要更改懒加载状态 g_lazy_status = 0,再次滑动符合条件即可再次加载数据
  • 相关阅读:
    环境变量
    多重继承
    参数检查(@property)
    限制属性绑定(__slots__)
    实例属性和类属性
    2017-11-28 中文编程语言之Z语言初尝试: ZLOGO 4
    2017-10-23 在各种编程语言中使用中文命名
    2017-11-27 汉化了十数个编译器的前辈的心得体会
    五行
    阴阳
  • 原文地址:https://www.cnblogs.com/yanruizhe/p/15146213.html
Copyright © 2011-2022 走看看