Skip to content

Instantly share code, notes, and snippets.

@Pustelto
Last active October 13, 2016 08:50
Show Gist options
  • Save Pustelto/9e374df765f89dd8ea1c0550ace60550 to your computer and use it in GitHub Desktop.
Save Pustelto/9e374df765f89dd8ea1c0550ace60550 to your computer and use it in GitHub Desktop.
Art direction for responsive SVG (usefull for responsive logos). Taken from www.arborvitae.skauting.cz, Modernizer media queries is necessary.
// SVG art-direction
const logoSvg = document.getElementById( 'av-logo' );
function artDirectSvg() {
if( Modernizr.mq( '(max-width: 300px)' ) ) {
logoSvg.setAttribute( 'viewBox', '0 0 79 85' );
}
if( Modernizr.mq( '(min-width: 300px)' ) && Modernizr.mq( '(max-width: 560px)' ) ) {
logoSvg.setAttribute( 'viewBox', '97 -230 403 310' );
}
if( Modernizr.mq( '(min-width: 561px)' ) ) {
logoSvg.setAttribute( 'viewBox', '0 0 500 85' );
}
}
artDirectSvg();
window.addEventListener( 'resize', artDirectSvg );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment