Skip to content

Instantly share code, notes, and snippets.

@cperryk
Last active September 30, 2015 19:32
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 cperryk/2d3250acac8a92a57aac to your computer and use it in GitHub Desktop.
Save cperryk/2d3250acac8a92a57aac to your computer and use it in GitHub Desktop.
Resize SVG height to fit contents using jQuery
function sizeSVG($svg){
var max_x = 0;
$svg.find('*').each(function(){
var bounding_rect = $(this)[0].getBoundingClientRect();
var x2 = bounding_rect.top + bounding_rect.height;
if(x2 > max_x){
max_x = x2;
}
});
$svg.css('height', max_x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment