One, native JavaScript pictures lazy loading
1. How to use, e.g.
// picture address to bind
2. Introduce the following native JavaScript code in the page
varLazy = { "IMG":NULL, "GetY":function(b) {varA = 0; if(b && b.offsetparent) while(b.offsetparent) A + = B.offsettop, B = b.offsetparent;Elseb && B.y && (A + =b.y); returnA; }, "GetX":function(b) {varA = 0; if(b && b.offsetparent) while(b.offsetparent) A + = B.offsetleft, B = b.offsetparent;Elseb && b.x && (A + =b.x); returnA; }, "Scrolly":function() { varA =document.documentelement; returnSelf.pageyoffset | | A && a.scrolltop | | Document.body.scrollTop | | 0; }, "SCROLLX":function() { varA =document.documentelement; returnSelf.pagexoffset | | A && A.scrollleft | | Document.body.scrollLeft | | 0; }, "WindowWidth":function() { varA =document.documentelement; returnSelf.innerwidth | | A && a.clientwidth | |Document.body.clientWidth; }, "WindowHeight":function() { varA =document.documentelement; returnSelf.innerheight | | A && a.clientheight | |Document.body.clientHeight; }, "Currentheight":function() { returnLazy.scrolly () +lazy.windowheight (); }, "Currentwidth":function() { returnLAZY.SCROLLX () +lazy.windowwidth (); }, "Load":function(d) {lazy.init (); varf = Lazy.currentheight (), B =lazy.currentwidth (); for(_index = 0; _index < Lazy.Img.length; _index++) { varA =Lazy.img[_index]; $ (a). attr ("lazy") = = undefined && $ (a). attr ("lazy", "n"); if($ (a). attr ("lazy") = = = "Y")Continue; /*$ (a). Bind ("Error", function () {this.id = = "Subject"? $ (this). attr ("src", ""): $ (this). attr ("src", "H Ttp://wap.cmread.com/rbc/p/content/repository/ues/image/s109/nopic.png "); });*/ if(d = = Undefined | | d = = "" | | D = =NULL) { varc = Lazy.gety (a), E =Lazy.getx (a); //E < b && C < f && (a.src = A.getattribute ("Data-src"), $ (a). attr ("lazy", "Y"), A.removeattribute ("DATA-SRC"));C < f && (a.src = A.getattribute ("Data-src"), $ (a). attr ("lazy", "Y"), A.removeattribute ("Data-src")); $ (a). attr ("Data-rel", E); } Else if(d = = "X") { varc =Lazy.getx (a); C< b && (a.src = A.getattribute ("Data-src"), $ (a). attr ("lazy", "Y")); } } }, "Init":function() { varA = Document.queryselectorall ("Img[data-src")); Lazy.img=A; }};//to bind a picture to a scroll axis lazy Load eventDocument.onscroll =function() {lazy.load ();}; SetTimeout (function() {lazy.load ();},100);//default configuration Lazy loading
JavaScript Native Picture lazy loading