Skip to content

Instantly share code, notes, and snippets.

@tamask
Created October 9, 2012 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamask/3859647 to your computer and use it in GitHub Desktop.
Save tamask/3859647 to your computer and use it in GitHub Desktop.
raphael.js|py and image fallback recipe
$('.art').each(function() {
var el, im, width, height, paper;
width = $(this).data('width');
if (width)
width += 'px';
height = $(this).data('height');
if (height)
height += 'px';
if (window.Raphael && (Raphael.svg || Raphael.vml)) {
el = $('<div>').addClass('svg');
im = IMAGES[$(this).data('vector')];
$(this).replaceWith(el);
if (!width)
width = im.width;
if (!height)
height = im.height;
el.css('width', width);
el.css('height', height);
paper = Raphael(el[0], '100%', '100%');
paper.setViewBox(0, 0, parseFloat(im.width), parseFloat(im.height), true);
im.fn(paper);
} else {
el = $('<img>').attr('src', $(this).data('pixel'));
$(this).replaceWith(el);
if (width)
el.css('width', width);
if (height)
el.css('height', height);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment