So, I have an SVG file in HTML, and one of the things I\'ve heard about the format is that it doesn\'t get all pixelated when you zoom in on it.
I know with a jpeg o
you can resize it by displaying svg in image tag and size image tag i.e.
<img width="200px" src="lion.svg"></img>
Here is an example of getting the bounds using svg.getBox()
:
https://gist.github.com/john-doherty/2ad94360771902b16f459f590b833d44
At the end you get numbers that you can plug into the svg to set the viewbox properly. Then use any css on the parent div and you're done.
// get all SVG objects in the DOM
var svgs = document.getElementsByTagName("svg");
var svg = svgs[0],
box = svg.getBBox(), // <- get the visual boundary required to view all children
viewBox = [box.x, box.y, box.width, box.height].join(" ");
// set viewable area based on value above
svg.setAttribute("viewBox", viewBox);