Copy viewBox from symbol rather than hardcoding

This commit is contained in:
Joe Fiorini
2015-05-01 10:25:23 -04:00
parent 3da0f37886
commit ec231bd516
2 changed files with 7 additions and 2 deletions

View File

@@ -12,10 +12,15 @@ export default function() {
// element's svg tag
var content = $(iconPath).clone();
// Copy classes off the <symbol> so that we preserve any styling
// Copy classes & viewBox off the <symbol> so that we preserve any styling
// when we copy the item inline
var classes = $(iconPath).attr('class');
// viewBox needs to be access via native
// javascript's setAttribute function
var viewBox = $(iconPath)[0].getAttribute('viewBox');
svg[0].setAttribute('viewBox', viewBox);
svg.attr('class', classes)
.html(content.contents());

View File

@@ -1,2 +1,2 @@
<svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 55 42" width="100%" height="100%">
<svg preserveAspectRatio="xMidYMid meet" width="100%" height="100%">
</svg>

Before

Width:  |  Height:  |  Size: 96 B

After

Width:  |  Height:  |  Size: 76 B