Skip to content

Latest commit

 

History

History
33 lines (28 loc) · 648 Bytes

图片懒加载.md

File metadata and controls

33 lines (28 loc) · 648 Bytes

图片懒加载

一个简单的布局,

<li class="img-item">
 <div class="img-wrap">
  <img src="img/d.jpg" class="list-img" data-src="{{img}}"/>
 </div>
 <div class="img-tt">
  <h1> {{name}} </h1>
 </div>
</li>
function imgLazyLoad(images) {
 var imgItem,
 cHeight = window.innerHeight || document.documentElement.clientHeight,
 sTop = document.documentElement.scrollTop || document.body.scrollTop,
 n = 0;

 for(var i = n; i < images.length; i++) {
  imgItem = images[i];
  if(imgItem.getAttribute('data-scr')) {
   imgItem.src = imgItem.getAttribute('data-src');
   imgItem.removeAttribute('data-src');
  }
  n++;
 }
}