Created
November 23, 2020 11:03
-
-
Save strokirk/ba702e972a5fc7bc41eabcd694f6a28d to your computer and use it in GitHub Desktop.
Calculate the viewBox of an SVG element
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
| function calculateViewBox(svgString) { | |
| // Get the bounding-box of a SVG element, formatted to use as it's viewBox | |
| let d = document.createElement("div") | |
| d.innerHTML = s | |
| document.body.appendChild(d) | |
| let r = d.firstElementChild.getBBox() | |
| return `${r.x} ${r.y} ${r.width} ${r.height}` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment