(function () {
Common
function TagName (tagName) {
Return document.getElementsByTagName (TagName);
}
function $ (ID) {
return document.getElementById (ID);
}
function Addevent (obj,type,func) {
if (Obj.addeventlistener) {
Obj.addeventlistener (Type,func,false);
}else if (obj.attachevent) {
Obj.attachevent (' on ' +type,func);
}
}
Set up some parameters
var v={
Elegroup:null,
Eletop:null,
Eleheight:null,
Screenheight:null,
Visibleheight:null,
Scrollheight:null,
Scrolloverheight:null,
Limitheight:null
}
Initialize the data
function init (Element) {
V.elegroup=tagname (Element)
Screenheight=document.documentelement.clientheight;
Scrolloverheight=document.body.scrolltop;
for (Var i=0,j=v.elegroup.length;i<j;i++) {
if (v.elegroup[i].offsettop<=screenheight && v.elegroup[i].getattribute (' asrc ')) {
V.elegroup[i].setattribute (' src ', v.elegroup[i].getattribute (' asrc '));
V.elegroup[i].removeattribute (' asrc ')
}
}
}
function Lazyload () {
if (Document.body.scrollTop = = 0) {
Limitheight=document.documentelement.scrolltop+document.documentelement.clientheight;
}else{
Limitheight=document.body.scrolltop+document.documentelement.clientheight;
}
for (Var i=0,j=v.elegroup.length;i<j;i++) {
if (v.elegroup[i].offsettop<=limitheight && v.elegroup[i].getattribute (' asrc ')) {
V.elegroup[i].src=v.elegroup[i].getattribute (' asrc ');
V.elegroup[i].removeattribute (' asrc ')
}
}
}
Init (' img ')
addevent (window, ' scroll ', lazyload);
})()
Picture Lazy Loading