guan

  博客园  :: 首页  :: 新随笔  :: 联系 ::  :: 管理
 /*
 分屏加载图片
 param:attr:存储图片src的属性
初始化 _that.loadImage("trueSrc")
*/
 , loadImage: function (attr) {
     var scrollTop = $(window).scrollTop(),
         wHeight = $(window).height();
     $("img[" + attr + "]").each(function (ele, index) {
         var _that = $(this),
             trueSrc = _that.attr(attr);
         if (trueSrc && _that.offset().top <= scrollTop + wHeight) {
             _that.attr("src", trueSrc).removeAttr(attr);
         }
     });
 }

调用:

$(".tab-panel-item").scroll(function () {
    mainfun.loadImage("data-src")
})
或
$(window).scroll(function () {
    mainfun.loadImage("data-src")
})

 

posted on 2017-11-16 14:31  麦田里的包米  阅读(354)  评论(0编辑  收藏  举报