Created
June 13, 2013 07:24
-
-
Save deniaz/5771826 to your computer and use it in GitHub Desktop.
SVG with PNG Fallback Example
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Easy use of SVG with PNG fallback</title> | |
<link rel="stylesheet" href="main.css"> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script> | |
</head> | |
<body> | |
<header> | |
<div id="logo"> | |
<img src="logo.svg" alt="Awesome Logo" data-png-fallback="logo.png" width="200" height="80" /> | |
</div> | |
</header> | |
[...] | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<script src="main.js"></script> | |
</body> | |
</html> |
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
#logo | |
{ | |
width: 200px; | |
height: 80px; | |
} |
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($) { | |
$(document).ready(function() { | |
if (!Modernizr.svg) { | |
var images = $('img[data-png-fallback]'); | |
images.each(function() { | |
$(this).attr('src', $(this).data('png-fallback')); | |
}); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment