宇筱博客

  • 解决办法
  • 学无止境
  • 记录时光
  • 百宝箱
宇筱博客
点滴记忆,汇聚成海。
  1. 首页
  2. 学无止境
  3. 正文

jquery实现下拉快到底部时加载更多数据

2023年5月8日 1381点热度 0人点赞 0条评论

实现原理:
获取浏览器高度  h = jQuery(window).height()
获取滚轮滚动高度  s = jQuery(window).scrollTop()
获取最页面总高度  documentH = jQuery(document).height()

当滚轮滚到距离页面底部100px时开始加载下一页数据

(s+h+100) >= documentH // 开始加载

但是会发现滚轮在接近页面底部100px后会多次加载

所以controller中定义全局变量 

var off_on = true

来控制只加载一次

jQuery(window).scroll(function () {
            var s = jQuery(window).scrollTop(),
                h = jQuery(window).height(),
                documentH = jQuery(document).height();
            if ((s + h + 100) >= documentH && $scope.isLastPage === false) {
                if (off_on) {
                    $scope.getData($scope.currentPage++, $scope.pageSize);
                    off_on = false;
                }
            }

        });

getdata(){}中获取下一页数据成功后,将off_on制为true

off_on = true

原文连接:点击进入

标签: 暂无
最后更新:2023年5月8日

小渔民

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2025 宇筱博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备15017825号-2