Created
January 28, 2016 10:24
-
-
Save munckymagik/399a7d8076fb3227c94f to your computer and use it in GitHub Desktop.
Work out SVG viewBox attribute values
This file contains hidden or 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
/* | |
* 1. Load your SVGs into a page using a <use> element. | |
* 2. Paste this into you developer console and run it. | |
* 3. It will print out the viewBox values you need for each SVG. | |
*/ | |
(() => { | |
'use strict'; | |
let f = (e) => { | |
let id = e.attributes['xlink:href'].value; | |
let b = e.getBBox(); | |
console.log(`id: ${id} viewBox="${b.x} ${b.y} ${b.width} ${b.height}"`); | |
} | |
let uses = Array.from(document.querySelectorAll('use')); | |
uses.forEach(f); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment