In my current project, I am utilizing JavaScript to determine the length of a path and apply half of that length to the stroke-DashArray
. However, I have encountered an issue as I am using
vector-effect="non-scaling-stroke"
in order to maintain a consistent stroke-width:2px;
regardless of scale. This property affects all aspects of the stroke properties, including DashArray, so I need to calculate the scale of the SVG in order to scale path.getTotalLength();
.
Is there a method in JavaScript to retrieve the computed scale of the SVG, which I can then use as a multiplier for the path length?
To illustrate this issue, I have created a demo on codepen.io. Feel free to resize the viewport to observe the changes in the stroke.