1 line
518 B
JavaScript
1 line
518 B
JavaScript
|
class LazyLoad{constructor(t){this.imglist=Array.from($(t)),this.init()}canILoad(){let t=this.imglist;for(let i=t.length;i--;)this.getBound(t[i])&&this.loadImage(t[i],i)}getBound(t){let i=t.getBoundingClientRect(),n=window.innerHeight;return i.top<=n}loadImage(t,i){let n=t.getAttribute("data-original");t.src=n,this.imglist.splice(i,1)}bindEvent(){$(window).on("scroll",()=>this.imglist.length&&this.canILoad()),$(window).on("resize",()=>this.imglist.length&&this.canILoad())}init(){this.canILoad(),this.bindEvent()}}
|