绑定滚动事件on-scroll
<ion-content on-scroll="scroll()"
// 可见区域的高度 var windowHeight = $(window).height(); $scope.scroll = function(){ lazyLoadImage(); } // repeat渲染结束后再lazyload $scope.$on('ngRepeatFinished', function(){ lazyLoadImage(); }) // lazyload的实现 function lazyLoadImage(){ var windowHeight = $(window).height(); imgCache = $('img.lazyload') imgCache.each(function(index, el) { if($(el).offset().top - windowHeight < -100){ var url = $(el).attr('data-url'); $(el).attr('src', url); $(el).removeClass('lazyload'); $(el).addClass('animated fadeIn'); } }); }end-repeat指令代码
.directive('endRepeat', ['$timeout', function ($timeout) { return { restrict: 'A', link: function (scope, element, attr) { if (scope.$last === true) { $timeout(function () { scope.$emit('ngRepeatFinished'); }); } } } }])模板代码
<img data-url="{{produce.produce_image}}" class="lazyload" ng-repeat="produce in produces" end-repeat>原理:将图片的src设置在data-url中,当随着页面滚动,图片进入可视区域时,将src设置为data-url的值
声明:
① 凡本网所有原创文章及图片、图表的版权均属WX部落所有,如需转载,需注明“信息来源:WX部落”,并且添加本文地址:http://wxbuluo.com/index/article/18.html
② 凡本网注明“来源:XXX(非WX部落)”的文字及图片内容,均转载自其他媒体,版权归原媒体及作者所有。转载目的在于传递更多的资讯,并不代表本网赞同其观点和对其真实性负责。如有侵权,请联系删除。联系方式:296720094@qq.com
③ 本网站的资源部分内容来源于网络,仅供大家学习与参考,如有侵权,请联系站长296720094@qq.com进行删除处理。
④ 部分项目课程具有时效性,如发布时间较长请搜索相关课程选择发布时间最近的查看。
⑤ 部分具有时效性的项目课程文章,我们会逐步转移到免费类分类开放下载。同时免费分类链接失效不补!
⑥ 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
2023 © wxbuluo.com ALL Rights Reserved. 鲁ICP备15005397号-1