Answer the question
In order to leave comments, you need to log in
How to calculate for all path their length?
Hello.
Available:
<svg id="svg-image">
<path/>
<rect/>
<path/>
</svg>
svg = $("#svg-image");
path = document.querySelector('path');
var pathLen = path.getTotalLength();
path.setAttribute('stroke-dasharray', pathLen);
var nS = 'http://www.w3.org/2000/svg';
var svgPaths = document.getElementsByTagNameNS(nS,'path');
for (var x = 0; x < svgPaths.length; x++) {
var path = svgPaths[x];
var pathDimensions = path.getTotalLength();
path.style.strokeDasharray = pathDimensions;
path.style.strokeDashoffset = pathDimensions;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question