Created
June 13, 2013 20:16
-
-
Save sardbaba/5776972 to your computer and use it in GitHub Desktop.
Fallback to PNG if SVG is not supported. Note: of course, you must create the PNG version of the SVG image.
Reference: http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function( $ ) { | |
$( window ).load( function() { | |
function supportsSVG() { | |
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect; | |
} | |
if (!supportsSVG()) { | |
var imgs = document.getElementsByTagName('img'); | |
var dotSVG = /.*\.svg$/; | |
for (var i = 0; i != imgs.length; ++i) { | |
if(imgs[i].src.match(dotSVG)) { | |
imgs[i].src = imgs[i].src.slice(0, -3) + 'png'; | |
} | |
} | |
} | |
} | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment