cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

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="wrapper">
    
    <section id="section-1" class="section">
        
        <h2 class="section-title">Section 1</h2>
        
        <button type="button" id="lazy-loader-section-1" class="lazy-loader">Charger les médias</button>
        
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        
        <img src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1510150567/blank_yqjp1i.png" data-src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1510150005/sea-min_rb9ifm.jpg" alt="Envie d'évasion ?" class="section-image" />
        
        <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        
        <iframe class="section-iframe" data-src="https://www.24joursdeweb.fr/2017/lancement/" allowfullscreen=""></iframe>
        
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
        
    </section>
    
    <section id="section-2" class="section">
        
        <h2 class="section-title">Section 2</h2>
        
        <button type="button" id="lazy-loader-section-2" class="lazy-loader">Charger les médias</button>
        
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        
        <img src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1510150567/blank_yqjp1i.png" data-src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1510149655/antibiotiques_pas_automatique_cjbnpc.png" alt="Les frameworks, c'est pas automatique" class="section-image" />
        
        <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        
        <div data-src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1509980892/24joursdeweb_pcxw8n.pdf" data-mediatype="pdf"></div>
        
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
        
    </section>
    
    <section id="section-3" class="section">
        
        <h2 class="section-title">Section 3</h2>
        
        <button type="button" id="lazy-loader-section-3" class="lazy-loader">Charger les médias</button>
        
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        
        <img src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1510150567/blank_yqjp1i.png" data-src="https://res.cloudinary.com/dnqehhgmu/image/upload/v1510149655/gorille_banane_rvqmsf.png" alt="You wanted a banana" class="section-image" />
        
        <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        
        <div data-src="https://res.cloudinary.com/dnqehhgmu/video/upload/v1509981466/rickroll_w11xqz.mp4" data-mediatype="video" title="Never gonna give you up"></div>
        
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
        
    </section>
    
</div>

            
          
!
            
              body {
  margin: 0;
}

* {
  font-family: "Open Sans", Arial, sans-serif;
  font-size: 14px;
}

.wrapper {
  width: 800px;
  max-width: 100%;
  margin: auto;
  overflow: hidden;
}

/* Sections : titres et boutons */

.section {
  padding: 20px;
  padding-top: 0;
}

.section-title {
  padding: 10px;
  text-align: center;
  font-size: 1.5em;
  text-transform: uppercase;
  background-color: #3AA996;
  color: #FFF;
}

.lazy-loader {
  display: block;
  width: 160px;
  padding: 10px;
  margin: auto;
  margin-bottom: 20px;
  text-align: center;
  border-radius: 5px;
  background-color: #0463B3;
  color: #FFF;
  border: none;
  cursor: pointer;
  -webkit-transition: background-color 0.25s ease-out;
  transition: background-color 0.25s ease-out;
}

.lazy-loader:hover,
.lazy-loader:focus {
  background-color: #3AA996;
}

/* Sections : contenus */


.section-image,
.section-video {
  display: block;
  max-width: 100%;
  margin: 10px auto;
}

.section-iframe {
  height: 0;
  border: 0;
}

.section-iframe[src],
.section-object {
  width: 100%;
  height: 400px;
  max-height: 70vh;
  border: 1px solid #CCC;
}
            
          
!
            
              /**
 * Chargement des medias dans un bloc identifié
 */
function mediaLazyLoading(containerId) {
    
    var lazySrc = document.querySelectorAll('#'+containerId+' *[data-src]');
    var lazySrcNb = lazySrc.length;
    for (var i=0;i<lazySrcNb;i++) {
        
        // Récupération des valeurs
        lazySrcCur = lazySrc[i];
        var mediaSrc = lazySrcCur.getAttribute('data-src');
        var title = '';
        if (lazySrcCur.title) {
            var title = lazySrcCur.title;
        }
        
        // Images et iframes
        if (lazySrcCur.tagName.toLowerCase()=='img' || lazySrcCur.tagName.toLowerCase()=='iframe') {
            lazySrcCur.src = mediaSrc;
            lazySrcCur.removeAttribute('data-src');
        }
        
        // Medias complexes
        else {
            
            var mediaText = '';
            switch (lazySrcCur.getAttribute('data-mediatype')) {
                
                // Vidéos
                case 'video' :
                    mediaText = '<video class="section-video" itemprop="url" title="'+title+'" alt="'+title+'" controls preload>';
                    mediaText += '<source itemprop="url" content="'+window.location.protocol+'//'+window.location.hostname+mediaSrc+'" src="'+mediaSrc+'" type="video/mp4" />';
                    mediaText += '<a href="'+mediaSrc+'" download>'+title+'</a>';
                    mediaText += '</video>';
                    break;
                
                // Pdf
                case 'pdf' :
                    mediaText = '<object class="section-object" data="'+mediaSrc+'" type="application/pdf" ></object>';
                    break;
                
            }
            
            lazySrcCur.innerHTML = mediaText;
            lazySrcCur.parentNode.insertBefore(lazySrcCur.childNodes[0],lazySrcCur)
            lazySrcCur.parentNode.removeChild(lazySrcCur);
            
        }
        
    }
    
}

/*
 * Evènements au clic
 */
document.getElementById('lazy-loader-section-1').addEventListener('click',function() {
    mediaLazyLoading('section-1');
},false);
document.getElementById('lazy-loader-section-2').addEventListener('click',function() {
    mediaLazyLoading('section-2');
},false);
document.getElementById('lazy-loader-section-3').addEventListener('click',function() {
    mediaLazyLoading('section-3');
},false);
            
          
!
999px
Loading ..................

Console