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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              ˆ<span data-picture>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can_mobile.jpg" data-width="100" data-height="110"></span>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can.jpg" data-media="(min-width: 800px)" data-width="259" data-height="285"></span>
    <noscript>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can_mobile.jpg"></span>
    </noscript>
</span>
<span data-picture>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_machine_opener_mobile.jpg" data-width="100" data-height="79"></span>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_machine_opener.jpg" data-media="(min-width: 800px)" data-width="500" data-height="399"></span>
    <noscript>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can_mobile.jpg"></span>
    </noscript>
</span>
<span data-picture>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/count_mobile.jpg"  data-width="100" data-height="93"></span>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/count.jpg" data-media="(min-width: 800px)" data-width="526" data-height="493"></span>
    <noscript>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can_mobile.jpg"></span>
    </noscript>
</span>
<span data-picture>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_with_opener_mobile.jpg" data-width="100" data-height="78"></span>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_with_opener.jpg" data-media="(min-width: 800px)" data-width="330" data-height="259"></span>
    <noscript>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can_mobile.jpg"></span>
    </noscript>
</span>
<span data-picture>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/extra_buttons_mobile.jpg" data-width="100" data-height="75" ></span>
    <span data-src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/extra_buttons.jpg" data-media="(min-width: 800px)" data-width="560" data-height="420"></span>
    <noscript>
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29218/coke_can_mobile.jpg"></span>
    </noscript>
</span>

            
          
!
            
              [data-picture] { border: 1px solid red; margin-bottom: 300px; display: block; }
            
          
!
            
              /* This is a customised version of picturefill.js with the following modifications

1. Before setting the source on the img tag to the appropriate img file, check if the lazyload plugin is defined

2. If so, set the data-original attr of the img instead of the src attr. Also set width and height attrs from the picture span's data-width and data-height attrs. 

3. Append the img tag and tell lazyload about it

*/

/*! Picturefill - Responsive Images that work today. (and mimic the proposed Picture element with span elements). Author: Scott Jehl, Filament Group, 2012 | License: MIT/GPLv2 */

(function( w ){

	// Enable strict mode
	"use strict";

	w.picturefill = function() {
		var ps = w.document.getElementsByTagName( "span" );

		// Loop the pictures
		for( var i = 0, il = ps.length; i < il; i++ ){
			if( ps[ i ].getAttribute( "data-picture" ) !== null ){

				var sources = ps[ i ].getElementsByTagName( "span" ),
					matches = [];

				// See if which sources match
				for( var j = 0, jl = sources.length; j < jl; j++ ){
					var media = sources[ j ].getAttribute( "data-media" );
					// if there's no media specified, OR w.matchMedia is supported 
					if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) ){
						matches.push( sources[ j ] );
					}
				}

			// Find any existing img element in the picture element
			var picImg = ps[ i ].getElementsByTagName( "img" )[ 0 ];

			if( matches.length ){
				var matchedEl = matches.pop();
				if( !picImg || picImg.parentNode.nodeName === "NOSCRIPT" ){
					picImg = w.document.createElement( "img" );
					picImg.alt = ps[ i ].getAttribute( "data-alt" );
				}

				// should we lazyload?
				if(jQuery.fn.lazyload){
					// check if src has changed
					if(picImg.getAttribute('data-original') != matchedEl.getAttribute( "data-src" )){
						// set data-original attr for lazyload.js
						picImg.setAttribute('data-original', matchedEl.getAttribute( "data-src" ));
						// set width and height for lazyload.js placeholder
						picImg.setAttribute('width', matchedEl.getAttribute( "data-width" ));
						picImg.setAttribute('height', matchedEl.getAttribute( "data-height" ));
						// append the new image
						matchedEl.appendChild( picImg );
						// tell lazyload.js about our new/modified image
						$(picImg).lazyload();	
					}
				}else{
					// default picturefill functionality
					picImg.src =  matchedEl.getAttribute( "data-src" );
					matchedEl.appendChild( picImg );
				}
			}
			else if( picImg ){
				picImg.parentNode.removeChild( picImg );
			}
		}
		}
	};

	// Run on resize and domready (w.load as a fallback)
	if( w.addEventListener ){
		w.addEventListener( "resize", w.picturefill, false );
		w.addEventListener( "DOMContentLoaded", function(){
			w.picturefill();
			// Run once only
			w.removeEventListener( "load", w.picturefill, false );
		}, false );
		w.addEventListener( "load", w.picturefill, false );
	}
	else if( w.attachEvent ){
		w.attachEvent( "onload", w.picturefill );
	}

}( this ));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console