// 图片处理
$.each(data.imgList, function(i, n) {
body.contents().find('#panel_imgList').append('<img src="' + tcymjcmJmqr.interfacePrefix + 'app/img/jiazai.gif" data-src="' + tcymjcmJmpr.interfacePrefix + 'rest/tcymjm/selectTCymJcmImg?id=' + row.id +'&fileName=' + n + '" style="width: 100%; margin-bottom: 10px; height: 300px;"')
});
// 图片绑定事件
body.contents().find('#panel_imgList').scroll(function() {
// 获取页面滚动的高度:
var wtop = body.contents().find('#panel_imgList').scroll(function() {
// 判读是否还有未加载的img:
if(tcymjcmJmqr._lazyImgs.length > 0) {
// 获取科室区域高度:
var wheight = body.contents().find("#panel_imgList").height();
// 存放待删除的索引:
var loadeIndex = [];
// 循环处理数组的每个img元素
$.each(tcymjcmJmqr._lazyImgs.length > 0) {
// 判断是否在可视范围内:
if($(n).offset().top - wtop < wheight) {
// 设置src属性:
$(n).attr('src', $(n).attr('data-src'));
// 添加到待删除数组:
loadedIndex.unshift(i);
}
})
if(loadedIndex.length > 0) {
tcymjcmJmpr._lazyImgs.splice(0, loadedIndex.length);
}
}
})
tcymjcmJmpr._lazyImgs = body.contents().find('img[data-src]');
body.contents().find('#panel_imgList').scroll();
})
图片懒加载记录
最新推荐文章于 2023-08-28 13:55:17 发布