cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container-fluid">
  <div class="row">
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 1" data-src="https://source.unsplash.com/ozwiCDVCeiw/450x450" data-srcset="https://source.unsplash.com/ozwiCDVCeiw/450x450 1x, https://source.unsplash.com/ozwiCDVCeiw/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/ozwiCDVCeiw/450x450" alt="Example photo 1" srcset="https://source.unsplash.com/ozwiCDVCeiw/450x450 1x, https://source.unsplash.com/ozwiCDVCeiw/900x900 2x" />
      </noscript>
    </div>
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 2" data-src="https://source.unsplash.com/SoC1ex6sI4w/450x450" data-srcset="https://source.unsplash.com/SoC1ex6sI4w/450x450 1x, https://source.unsplash.com/SoC1ex6sI4w/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/SoC1ex6sI4w/450x450" alt="Example photo 2" srcset="https://source.unsplash.com/SoC1ex6sI4w/450x450 1x, https://source.unsplash.com/SoC1ex6sI4w/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 3" data-src="https://source.unsplash.com/oXo6IvDnkqc/450x450" data-srcset="https://source.unsplash.com/oXo6IvDnkqc/450x450 1x, https://source.unsplash.com/oXo6IvDnkqc/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/oXo6IvDnkqc/450x450" alt="Example photo 3" srcset="https://source.unsplash.com/oXo6IvDnkqc/450x450 1x, https://source.unsplash.com/oXo6IvDnkqc/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 4" data-src="https://source.unsplash.com/gjLE6S4omY0/450x450" data-srcset="https://source.unsplash.com/gjLE6S4omY0/450x450 1x, https://source.unsplash.com/gjLE6S4omY0/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/gjLE6S4omY0/450x450" alt="Example photo 4" srcset="https://source.unsplash.com/gjLE6S4omY0/450x450 1x, https://source.unsplash.com/gjLE6S4omY0/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 5" data-src="https://source.unsplash.com/KeUKM5N-e_g/450x450" data-srcset="https://source.unsplash.com/KeUKM5N-e_g/450x450 1x, https://source.unsplash.com/KeUKM5N-e_g/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/KeUKM5N-e_g/450x450" alt="Example photo 5" srcset="https://source.unsplash.com/KeUKM5N-e_g/450x450 1x, https://source.unsplash.com/KeUKM5N-e_g/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 6" data-src="https://source.unsplash.com/gjLE6S4omY0/450x450" data-srcset="https://source.unsplash.com/gjLE6S4omY0/450x450 1x, https://source.unsplash.com/gjLE6S4omY0/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/gjLE6S4omY0/450x450" alt="Example photo 6" srcset="https://source.unsplash.com/gjLE6S4omY0/450x450 1x, https://source.unsplash.com/gjLE6S4omY0/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 7" data-src="https://source.unsplash.com/7eKCe28OG6E/450x450" data-srcset="https://source.unsplash.com/7eKCe28OG6E/450x450 1x, https://source.unsplash.com/7eKCe28OG6E/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/7eKCe28OG6E/450x450" alt="Example photo 7" srcset="https://source.unsplash.com/7eKCe28OG6E/450x450 1x, https://source.unsplash.com/7eKCe28OG6E/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 8" data-src="https://source.unsplash.com/0Pz4h4_O3PU/450x450" data-srcset="https://source.unsplash.com/0Pz4h4_O3PU/450x450 1x, https://source.unsplash.com/0Pz4h4_O3PU/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/0Pz4h4_O3PU/450x450" alt="Example photo 8" srcset="https://source.unsplash.com/0Pz4h4_O3PU/450x450 1x, https://source.unsplash.com/0Pz4h4_O3PU/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 9" data-src="https://source.unsplash.com/cFplR9ZGnAk/450x450" data-srcset="https://source.unsplash.com/cFplR9ZGnAk/450x450 1x, https://source.unsplash.com/cFplR9ZGnAk/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/KeUKM5N-e_g/450x450" alt="Example photo 9" srcset="https://source.unsplash.com/cFplR9ZGnAk/450x450 1x, https://source.unsplash.com/cFplR9ZGnAk/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 10" data-src="https://source.unsplash.com/UO02gAW3c0c/450x450" data-srcset="https://source.unsplash.com/UO02gAW3c0c/450x450 1x, https://source.unsplash.com/UO02gAW3c0c/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/UO02gAW3c0c/450x450" alt="Example photo 10" srcset="https://source.unsplash.com/UO02gAW3c0c/450x450 1x, https://source.unsplash.com/UO02gAW3c0c/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 11" data-src="https://source.unsplash.com/3FjIywswHSk/450x450" data-srcset="https://source.unsplash.com/3FjIywswHSk/450x450 1x, https://source.unsplash.com/3FjIywswHSk/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/3FjIywswHSk/450x450" alt="Example photo 11" srcset="https://source.unsplash.com/3FjIywswHSk/450x450 1x, https://source.unsplash.com/3FjIywswHSk/900x900 2x" />
      </noscript>
    </div>
    
    <div class="col-md-2 col-lg-3">
      <img alt="Example photo 12" data-src="https://source.unsplash.com/z_L0sZoxlCk/450x450" data-srcset="https://source.unsplash.com/z_L0sZoxlCk/450x450 1x, https://source.unsplash.com/z_L0sZoxlCk/900x900 2x" class="lazy" />
      
      <noscript>
        <img src="https://source.unsplash.com/z_L0sZoxlCk/450x450" alt="Example photo 12" srcset="https://source.unsplash.com/z_L0sZoxlCk/450x450 1x, https://source.unsplash.com/z_L0sZoxlCk/900x900 2x" />
      </noscript>
    </div>
  </div>
</div>
            
          
!
            
              /* Hide lazyload images if JavaScript is not supported */
.no-js .lazy {
  display: none;
}

/* Avoid empty images to appear as broken */
img:not([src]):not([srcset]) {
  visibility: hidden;
}

/* Fix for images to never exceed the width of the container */
img {
  max-width: 100%;
}
            
          
!
            
              (() => {
  const lazyloadVanilla = () => {
    // Test if image is in the viewport
    const isImageInViewport = (img) => {
      const rect = img.getBoundingClientRect();

      return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
      );
    }

    // Create custom fading effect for showing images
    const fadeInCustom = (element) => {
      let elementOpacity = 0.1;// initial opacity

      element.style.display = 'block';

      const timer = setInterval(() => {
        if (elementOpacity >= 1){
          clearInterval(timer);
        }

        element.style.opacity = elementOpacity;

        element.style.filter = 'alpha(opacity=' + elementOpacity * 100 + ")";

        elementOpacity += elementOpacity * 0.1;
      }, 15);
    };

    // lazyloadVanilla function
    const lazyloadVanillaLoader = () => {
      const lazyImagesList = document.querySelectorAll('img[data-src]');
      
      lazyImagesList.forEach((image) => {
        if (isImageInViewport(image)) {
          if (image.getAttribute('data-src') !== null) {
            image.setAttribute('src', image.getAttribute('data-src'));

            image.removeAttribute('data-src');
          }

          if (image.getAttribute('data-srcset') !== null) {
            image.setAttribute('srcset', image.getAttribute('data-srcset'));

            image.removeAttribute('data-srcset');
          }

          image.setAttribute('data-loaded', true);

          fadeInCustom(image);
        }
      });

      // Remove event listeners if all images are loaded
      if (document.querySelectorAll('img[data-src]').length === 0 && document.querySelectorAll('img[data-srcset]')) {
        window.removeEventListener('DOMContentLoaded', lazyloadVanilla);

        window.removeEventListener('load', lazyloadVanillaLoader);

        window.removeEventListener('resize', lazyloadVanillaLoader);

        window.removeEventListener('scroll', lazyloadVanillaLoader);
      }
    };

    // Add event listeners to images
    window.addEventListener('DOMContentLoaded', lazyloadVanillaLoader);

    window.addEventListener('load', lazyloadVanillaLoader);

    window.addEventListener('resize', lazyloadVanillaLoader);

    window.addEventListener('scroll', lazyloadVanillaLoader);
  }
  
  // Test if JavaScript is available and allowed
  if (document.querySelector('.no-js') !== null) {
    document.querySelector('.no-js').classList.remove('no-js');
  }
  
  // Initiate lazyloadVanilla plugin
  return lazyloadVanilla();
})();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console