最近研究了京东商城用jQuery的实现如下
就是默认地址赋给img标签的src属性显示时赋给src属性值
复制代码 代码如下:
function lazyload(option) {
var settings = {
defObj: null
defHeight:
};
settings = $extend(settings option || {});
var defHeight = settingsdefHeight;
var defObj = (typeof settingsdefObj == "object") ? settingsdefObjfind("img") : $(settingsdefObj)find("img");
var pageTop = function() {
return documentdocumentElementclientHeight + Mathmax(documentdocumentElementscrollTop documentbodyscrollTop) settingsdefHeight;
};
var imgLoad = function() {
defObjeach(function() {
if ($(this)offset()top <= pageTop()) {
var src = $(this)attr("src");
//已显示的不用再显示
if (src) {
//显示后去掉src属性
$(this)attr("src" src)removeAttr("src");
}
}
});
};
imgLoad();
$(window)bind("scroll" function() {
imgLoad();
});
}
lazyload({
defObj:"w"
});