MUI - 解决动态列表页图片懒加载再次加载不成功的bug

首先描述一下功能

实现列表页动态加载
通过官方提供的"下拉刷新和上拉刷新"及"图片懒加载"示例实现。

http://www.cnblogs.com/phillyx/

然后说一下bug

  1. 首次加载时图片可以获取成功,
  2. 再次加载失败,通过chrome调试发现img 的 data-lazyload 属性没改变
  3. 调试的时候发现了bug
$.fn.imageLazyload = function(options) {
            var lazyloadApis = [];
            this.each(function() {
                var self = this;
                var lazyloadApi = null;
                if (self === document || self === window) {
                    self = document.body;
                }
 //对,bug就在这,判定时如果body已有该属性,就不在加载了,整体的代码没看明白,注释太少了啊
                var id = self.getAttribute('data-imageLazyload');
                if (!id) {
                    id = ++$.uuid;
                    $.data[id] = lazyloadApi = new ImageLazyload(self, options);
                    self.setAttribute('data-imageLazyload', id);
                } else {
                    lazyloadApi = $.data[id];
                }
                lazyloadApis.push(lazyloadApi);
            });
            return lazyloadApis.length === 1 ? lazyloadApis[0] : lazyloadApis;
        }
  1. 问题找到了,那么就在再次加载数据时,清除该属性就ok了
  document.body.removeAttribute('data-imagelazyload');
        mui(document).imageLazyload({
            placeholder: '../../images/img_head3.png'
        });

END

那么问题来了:

为什么会这么考虑,还有其他的解决方案么?

最新的解决方案参考DCloud问答的官方回复

转载于:https://www.cnblogs.com/phillyx/p/4552470.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一款基于mui框架制作的选项卡切换和下拉刷新加载数据列表代码,手机移动端选项卡切换插件,触屏滑动下拉刷新代码。 js代码 [removed][removed] [removed][removed] [removed][removed] [removed] mui.init(); (function($) { //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; $('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); $.ready(function() { //循环初始化所有下拉刷新,上拉加载。 $.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) { $(pullRefreshEl).pullToRefresh({ down: { callback: function() { var self = this; setTimeout(function() { var ul = self.element.querySelector('.mui-table-view'); ul.insertBefore(createFragment(ul, index, 10, true), ul.firstChild); self.endPullDownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function() { var ul = self.element.querySelector('.mui-table-view'); ul.appendChild(createFragment(ul, index, 5)); self.endPullUpToRefresh(); }, 1000); } } }); }); var createFragment = function(ul, index, count, reverse) { var length = ul.querySelectorAll('li').length; var fragment = document.createDocumentFragment(); var li; for (var i = 0; i < count; i ) { li = document.createElement('li'); li.className = 'mui-table-view-cell'; li[removed] = '第' (index 1) '个选项卡子项-' (length (reverse ? (count - i) : (i 1))); fragment.appendChild(li); } return fragment; }; }); })(mui); [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值