Last active
September 30, 2015 19:32
-
-
Save cperryk/2d3250acac8a92a57aac to your computer and use it in GitHub Desktop.
Resize SVG height to fit contents using jQuery
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 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