Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <h2>Try Scrolling to Bottom</h2>

<p>
  <img class="alignleft" data-src="https://picsum.photos/id/1/200/150">
  Consectetur adipisicing elit. Minus odio, obcaecati impedit voluptates rerum nisi reprehenderit dicta expedita in ut molestias cumque atque! Esse architecto. dolorem consequatur veniam provident modi. Dolor obcaecati nesciunt aperiam corrupti repellendus nihil illo velit voluptatem totam architecto sit eligendi, cumque eum animi eveniet id, veniam omnis necessitatibus explicabo ipsum assumenda expedita hic sunt! Reprehenderit nihil deserunt, incidunt facilis voluptates culpa suscipit illo.</p>

<p>
  Commodi deserunt hic amet impedit vitae nemo, in enim sit, provident eius eligendi ullam molestiae asperiores quaerat doloremque nulla molestias? Assumenda iusto, sunt eaque natus accusamus deleniti magnam, dignissimos corporis impedit, officia 
</p>

<img class="hero" data-src="https://picsum.photos/id/10/800/200">

<p>Incidunt cumque iure ab, voluptatem deserunt autem quibusdam similique sit cupiditate labore eaque, nihil voluptate asperiores dolorem.</p>

<p> <img class="alignright" data-src="https://picsum.photos/id/25/200/110"> Vero quae vitae excepturi voluptas aperiam perferendis eum doloribus dolores culpa aliquid, esse voluptatum cum quasi perspiciatis laborum harum, iste, totam modi. Quas quo corporis libero id harum quod earum, odio accusantium quia necessitatibus quos. Voluptate similique perferendis totam quod amet quasi rem veritatis vel ab sapiente. Necessitatibus tempora quisquam qui aperiam nesciunt totam delectus at in vitae! 
</p>

<p>Fuga fugit sit dolores laboriosam, saepe natus eligendi voluptatem officiis dolor commodi maxime distinctio, eveniet minus consequuntur.</p>

<p>Dicta possimus nostrum quisquam veritatis unde voluptas quam doloribus a nemo ipsa! Assumenda odit eveniet totam molestias aliquam incidunt.</p>

<img class="hero" data-src="https://picsum.photos/id/50/800/300">

<h3>Deleniti beatae porro omnis eligendi molestias</h3>
<p>
  <img class="alignleft" data-src="https://picsum.photos/id/75/200/120">
  Ducimus aliquam totam provident maiores harum, sunt in excepturi atque eum maxime deserunt quasi! Culpa praesentium quia voluptatibus est, nemo possimus sapiente incidunt ad, deserunt veniam maxime, eius rem molestiae doloremque. Iste tenetur molestiae voluptate optio obcaecati, vitae.</p>
<p>
  Consectetur adipisicing elit. Minus odio, obcaecati impedit voluptates rerum nisi reprehenderit dicta expedita in ut molestias cumque atque! Esse architecto.</p>

<img class="hero" data-src="https://picsum.photos/id/100/800/200">

<p>Incidunt cumque iure ab, voluptatem deserunt autem quibusdam similique sit cupiditate labore eaque, nihil voluptate asperiores dolorem. Perferendis mollitia illum cum ipsum quo, fuga aliquid ex porro reiciendis cupiditate rem ipsa error illo atque? Modi non, dolorum pariatur maiores praesentium amet eum alias neque nesciunt. </p>

<p><img class="alignright" data-src="https://picsum.photos/id/120/200/100">Vero quae vitae excepturi voluptas aperiam perferendis eum doloribus dolores culpa aliquid, esse voluptatum cum quasi perspiciatis laborum harum, iste, totam modi.
</p>

<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus molestiae voluptates, culpa, laboriosam cumque modi exercitationem laborum voluptatum.</p>

<img class="hero" data-src="https://picsum.photos/id/250/800/300">
            
          
!

CSS

            
              body { padding: 1rem; max-width: 480px; }
p { font-size: 18px; }
img { max-width: 100%; }
.alignleft { float: left; margin-right: 1rem; }
.alignright { float: right; margin-left: 1rem; }
            
          
!

JS

            
              ( function() { 'use strict';
  let images = document.querySelectorAll('img[data-src]');
              
  document.addEventListener('DOMContentLoaded', onReady);
  function onReady() {
    // Show above-the-fold images first
    showImagesOnView();

    // scroll listener
    window.addEventListener( 'scroll', showImagesOnView, false );
  }
  
  // Show the image if reached on viewport
  function showImagesOnView( e ) {
    
    for( let i of images ) {
      if( i.getAttribute('src') ) { continue; } // SKIP if already displayed
      
      // Compare the position of image and scroll
      let bounding = i.getBoundingClientRect();
      let isOnView = bounding.top >= 0 &&
      bounding.left >= 0 &&
      bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
      bounding.right <= (window.innerWidth || document.documentElement.clientWidth);
      
      if( isOnView ) {
        i.setAttribute( 'src', i.dataset.src );
        if( i.getAttribute('srcset') ) {
          i.setAttribute( 'srcset', i.dataset.srcset );
        }
      }
    }
  }
              
})();
            
          
!
999px

Console