Skip to content

Instantly share code, notes, and snippets.

@pfulton
Created December 11, 2012 15:31
Show Gist options
  • Save pfulton/4259378 to your computer and use it in GitHub Desktop.
Save pfulton/4259378 to your computer and use it in GitHub Desktop.
Webkit SVG height bugfix
// jQuery fix for Webkit SVG height bug.
// Documented here: https://bugs.webkit.org/show_bug.cgi?id=82489 & http://www.brichards.co.uk/blog/webkit-svg-height-bug-workaround
// Found via: http://stackoverflow.com/questions/7570917/svg-height-incorrectly-calculated-in-webkit-browsers
function fixWebkitHeightBug(){
var svgW = 658;
var svgH = 500;
var curSVGW = $('#svg-container').width();
var newSVGH = heightInRatio(svgH,svgW,curSVGW);
$('#svg-container').height(newSVGH);
function heightInRatio(oH,oW,nW){
return (oH / oW * nW);
}
};
$(window).resize(function() {
fixWebkitHeightBug();
});
$(document).ready(function() {
fixWebkitHeightBug();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment