B
B
beefront172019-03-11 17:48:02
JavaScript
beefront17, 2019-03-11 17:48:02

How to set viewbox for tag, svg?

Good afternoon! Can you please tell me how to set a viewbox or something for the svg tag?
The problem is that there is such markup.

<g><circle cx="10" cy="10" r="4"  stroke-width: 0;"></circle></g>

And I need to animate the stroke-width and when animating it turns out that the stroke-width goes beyond the g tag and the result is a square and not a circle.
How to fix it?
Thank you in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2019-03-11
@beefront17

let svg = document.getElementsByTagName('svg')[0];
svg.setAttribute('viewBox',"0 0 400 400");

But you do not need this, you need to shift g to the height and width of the future stroke-width / 2
<g transform="translate(2,2)"><circle cx="10" cy="10" r="4"  stroke-width="0"></circle></g>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question