Skip to content

Instantly share code, notes, and snippets.

@CaseyLeask
Created October 30, 2013 00:25
Show Gist options
  • Save CaseyLeask/7225174 to your computer and use it in GitHub Desktop.
Save CaseyLeask/7225174 to your computer and use it in GitHub Desktop.
( function ( document, metaQuery) {
var imageElements = document.getElementsByTagName( 'img' ),
updateElements = function ( matches, name ) {
if ( !matches ) { return; }
imageElements.forEach( setSrc );
},
setSrc = function ( element ) {
var template = element.getAttribute( 'data-mq-src' );
if ( template ) {
element.src = template.replace( '[breakpoint]', name );
}
};
metaQuery.onBreakpointChange( function ( matches, breakpointName ) {
updateElements ( matches, breakpointName );
});
}( document, metaQuery ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment