I
I
IvanKalinin2015-10-29 22:46:47
JavaScript
IvanKalinin, 2015-10-29 22:46:47

How to draw an SVG circle with a given block width/height using JavaScript?

All good time.
The task is next.
There is a square block with dynamic dimensions. How to use JS (knowing the height and width of the block) to draw the correct circle path inside the block with its dimensions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Dubrovsky, 2015-10-29
@IvanKalinin

Hello. If you need a circle, then you don't need a path, you need a circle:
jsfiddle.net/qnmy8kay
Accordingly, insert the necessary values ​​into its attributes.

D
Denis Ineshin, 2015-10-29
@IonDen

You can draw a circle without SVG!

.test {
    width: 100px;
    height: 100px;
    background: #000;
    border-radius: 50%; // вот так
}

If you still need it a lot, then it is better to use a special one. libraries. You'll be confused about calculating the path yourself.
d3js.org
raphaeljs.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question