Skip to content

Instantly share code, notes, and snippets.

@munckymagik
Created January 28, 2016 10:24
Show Gist options
  • Save munckymagik/399a7d8076fb3227c94f to your computer and use it in GitHub Desktop.
Save munckymagik/399a7d8076fb3227c94f to your computer and use it in GitHub Desktop.
Work out SVG viewBox attribute values
/*
* 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