Lazy Loading Images - CSS-Tricks

Inhaltsverzeichnis

UPDATE: Das ist ziemlich alt. Wenn Sie heutzutage faul Bilder laden möchten, empfehlen wir Ihnen:

  • Die vollständige Anleitung zum verzögerten Laden von Bildern
  • Eine native Lazy Load für die Webplattform
  • Tipps zum Rollen Ihres eigenen faulen Ladens

Verwenden Sie a 5699899/lazy_loading_images_css-tricks.gifals srcvon Bildern und fügen Sie das widthund heightdes endgültigen Bildes hinzu.

/* lazyload.js (c) Lorenzo Giuliani * MIT License (http://www.opensource.org/licenses/mit-license.html) * * expects a list of: * `` */ !function(window)( var $q = function(q, res)( if (document.querySelectorAll) ( res = document.querySelectorAll(q); ) else ( var d=document , a=d.styleSheets(0) || d.createStyleSheet(); a.addRule(q,'f:b'); for(var l=d.all,b=0,c=(),f=l.length;b  = 0 && rect.left >= 0 && rect.top <= (window.innerHeight || document.documentElement.clientHeight) ) ) var images = new Array() , query = $q('img.lazy') , processScroll = function()( for (var i = 0; i < images.length; i++) ( if (elementInViewport(images(i))) ( loadImage(images(i), function () ( images.splice(i, i); )); ) ); ) ; // Array.prototype.slice.call is not callable under our lovely IE8 for (var i = 0; i < query.length; i++) ( images.push(query(i)); ); processScroll(); addEventListener('scroll',processScroll); )(this); 

Sehen Sie sich den Pen
Lazy Loading Images von Chris Coyier (@chriscoyier)
auf CodePen an.

Interessante Beiträge...