Код: Выделить всё
viewBoxАтрибут
Пример:
Код: Выделить всё
const drawingArea = document.querySelector('#drawing-area');
drawingArea.addEventListener('click', (e) => {
const { left, top } = drawingArea.getBoundingClientRect();
drawCircle({
x: e.clientX - left,
y: e.clientY - top});
});
const drawCircle = ({ x, y }, r = 10) => {
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('cx', x.toString());
circle.setAttribute('cy', y.toString());
circle.setAttribute('r', r.toString());
drawingArea.appendChild(circle);
}
const translateToSVGCoordinates = (x, y) => {
const point = drawingArea.createSVGPoint();
point.x = x;
point.y = y;
point.matrixTransform(drawingArea.getScreenCTM().inverse());
return { x: point.x, y: point.y };
}
Код: Выделить всё
body, html {
width: 100%;
height: 100%;
margin: 0;
}
Код: Выделить всё
Если мне было недостаточно ясно, что ожидаемый результат, просто удалите
Код: Выделить всё
viewBoxАтрибут
Подробнее здесь: https://stackoverflow.com/questions/683 ... oordinates