Skip to content

Instantly share code, notes, and snippets.

@deniaz
Created June 13, 2013 07:24
Show Gist options
  • Save deniaz/5771826 to your computer and use it in GitHub Desktop.
Save deniaz/5771826 to your computer and use it in GitHub Desktop.
SVG with PNG Fallback Example
<!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>
#logo
{
width: 200px;
height: 80px;
}
(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