How to get the updated "d" attribute from a staggered SVG path

Asked

Viewed 45 times

0

Well, I have the following code by which I take the contents of the "d" attribute of a <path> SVG, however, need updated coordinates after using scale to increase the size of the drawing, because when I request to increase or decrease the scale, I have the same values as the initial coordinates.

<!doctype html>
<html lang="pt-BR">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
	.xxx {
		color:blue;
	}
	</style>
</head>
<body>
<svg>
 <path id="xxx" d="M100,10 L150,10 L150,60"
    style="stroke: #6666ff; stroke-width: 1px; fill: none;
            marker-start: url(#markerCircle);
            marker-end: url(#markerArrow);"
        />

</svg>
	
	<script>
	console.log(document.getElementById('xxx').getAttribute('d'));
	document.getElementById('xxx').style.transform='scale(2)';
	console.log(document.getElementById('xxx').getAttribute('d'));
	</script>
</body>
</html>

Any hint!

  • Guy doesn’t know exactly the application there, but the interesting thing would be the SVG having a viewbox, and the d begin in 0,0 of that viewbox, from there you make the Scale() of the SVG as a whole

  • Sorry for the delay. It’s just that the way you suggested it doesn’t fit because the dneed to have freedom to be positioned in any position on the screen. There is no function that stores the coordinates of the <path> the moment he is staggered?

  • Ai can’t say, but maybe you can put a svg on top of each other all with 100% of the height and width of the element that are overlapping, but I don’t know if it would help you in something, you can also lock the Transform-oringe in the top left for example to try to keep x y fixed in one place

  • Hey, when I said whether there’s a function that stores the coordinates of the <path>when staggered, I meant the new value of the coordinates, because I want to be able to access the coordinates of the position of the drawing on the screen, after a scale, understood? I mean, when I have: <path id="xxx" d="M100,10 L150,10 L150,60" and use scale(5), for example, I want the coordinates of the drawing already in the new size. However, in the DOM, the value of dcontinues the initial.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.