Capítulo 161 de 411
A helper that converts every anchor point along an SVG path into its progress value (0-1) relative to the path's total length, so you can drive point-by-point animation (e.g. with DrawSVG) instead of only smooth continuous motion. Requires MotionPathPlugin.
MotionPathPlugin.getRawPath()).MotionPathPlugin.cacheRawPathMeasurements() at a given sampling resolution to measure segment lengths.0.function anchorsToProgress(rawPath, resolution) {
resolution = ~~resolution || 12;
if (!Array.isArray(rawPath)) rawPath = MotionPathPlugin.getRawPath(rawPath);
MotionPathPlugin.cacheRawPathMeasurements(rawPath, resolution);
let progress = [0], length, s, i, e, segment, samples;
for (s = 0; s < rawPath.length; s++) {
segment = rawPath[s];
samples = segment.samples;
e = segment.length - 6;
for (i = 0; i < e; i += 6) {
length = samples[(i / 6 + 1) * resolution - 1];
progress.push(length / rawPath.totalLength);
}
}
return progress;
}
gsap.registerPlugin(MotionPathPlugin).resolution improves measurement accuracy at the cost of computation.