扫码关注官方订阅号
如何实现angular的懒加载,每次加载10条数据,滑到底部再次加载10条数据
学习是最好的投资!
写个directive,然后在里面监听滚动,滚动结束后判断是不是到了底部,如果到了底部再回调。
随手写了一截代码,未测试,尽管使用,错了再改。
app.directive('scrollOnBottom', [function() { return { restrict: 'AE', scope: { scrollOnBottom: '&', selfEle: '=' }, link: link }; function link(scope, ele, attr) { var target = window; var element = document.body; if (scope.selfEle) { target = ele[0]; element = ele[0]; } target.addEventListener('scroll', scorllHandle, false); function scorllHandle(ev) { if (getRect(element).isBottom) scope.scrollOnBottom({$event: ev}); } scope.$on('$destroy', function() { target.removeEventListener('scroll', scorllHandle, false); }); } function getRect(ele){ var inHeight=window.innerHeight; var rect=ele.getBoundingClientRect(); // rect.isVisible = rect.top - inHeight<0; // 是否在可视区域 rect.isBottom = rect.bottom - inHeight<=0; return rect; } }]);
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
写个directive,然后在里面监听滚动,滚动结束后判断是不是到了底部,如果到了底部再回调。
随手写了一截代码,未测试,尽管使用,错了再改。