Created
August 8, 2014 09:39
-
-
Save jamielovelace/cb7022bf465a5188c792 to your computer and use it in GitHub Desktop.
Replace .svg with .png - with modernizr
This file contains hidden or 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
| /* | |
| * Thanks to Todd Motto ( @toddmotto ) | |
| * http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/ | |
| */ | |
| if(!Modernizr.svg) { | |
| var imgs = document.getElementsByTagName('img'); | |
| var endsWithDotSvg = /.*\.svg$/ | |
| var i = 0; | |
| var l = imgs.length; | |
| for(; i != l; ++i) { | |
| if(imgs[i].src.match(endsWithDotSvg)) { | |
| imgs[i].src = imgs[i].src.slice(0, -3) + 'png'; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment