I'm trying to animate SVG on scroll, i've created the SVG path my self using math, and it's showing as what i need exactly, but the problem started when i tried to add effect on path using CSS stroke-dasharray
my problem is : the animation starts from two points, one from the start, and the other after the q command, as long as i used move command twice, one at the start and one after q curve command.
i tried to fix this all the way, but it changes the drawn SVG totally.
here is a snippet to explain more how it works with me,
const shape = document.querySelector('#shape');
window.addEventListener('scroll', slide);
function slide() {
let value = 2000 - scrollY*4;
shape.style.strokeDashoffset= value;
}
body {
background:black;
-webkit-user-select:none;
}
#svgdiv {
position:fixed;
margin:auto;
top:1rem;
width:95%;
}
#div1 {
height:30rem;
}
#shape {
stroke-dashoffset:2000;
stroke-dasharray: 2000;
}
#shapebg {
stroke-dashoffset:2000;
stroke-dasharray: 0;
}
#div2 {
height:19rem;
}
<div id="div1"></div>
<div id="svgdiv">
<svg viewBox="0 0 1080 500">
<path id="shape" d="M 0 0 10 0 10 0 10 50 10 50 40 50 40 50 40 120 40 120 235 120 235 120 235 50 235 50 q 450 -20 290 130 M 525 180 595 220 595 220 605 300 605 300 675 250 675 250 725 320 725 320 765 255 765 255 835 260 835 260 810 200 810 200 890 70 890 70 1050 130 1050 130 1040 260 1040 260 880 270 880 270 1079 300" stroke="purple" stroke-width="1.5" fill="none" />
<path id="shapebg" d="M 0 0 10 0 10 0 10 50 10 50 40 50 40 50 40 120 40 120 235 120 235 120 235 50 235 50 q 450 -20 290 130 M 525 180 595 220 595 220 605 300 605 300 675 250 675 250 725 320 725 320 765 255 765 255 835 260 835 260 810 200 810 200 890 70 890 70 1050 130 1050 130 1040 260 1040 260 880 270 880 270 1079 300" stroke="purple" stroke-width="0.6" fill="none" />
</svg>
</div>
<div id="div2">
</div>
as you can see it starts from two points, but i need the animation to start from scratch and go to end directly,
any hints please ?