/* 分屏加载图片 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") })