diff --git a/web/src/sections/Concepts.tsx b/web/src/sections/Concepts.tsx index ec1cfd5..82f082b 100644 --- a/web/src/sections/Concepts.tsx +++ b/web/src/sections/Concepts.tsx @@ -45,16 +45,49 @@ function ChartBackdrop() { window.matchMedia('(prefers-reduced-motion: reduce)').matches; let raf = 0; + // wygładzony postęp (sprężyna) — animacja idzie z opóźnieniem i delikatnym bouncingiem + let target = 0; + let shown = 0; + let vel = 0; + let frame = 0; + + const paint = () => { + const e = Math.min(Math.max(shown, 0), 1); + line.style.strokeDashoffset = String(len * (1 - e)); + line2.style.strokeDashoffset = String(len2 * (1 - e)); + clip.setAttribute('width', String(e * 1000)); + clip2.setAttribute('width', String(e * 1000)); + }; + + const run = () => { + const d = target - shown; + if (Math.abs(d) < 0.0008 && Math.abs(vel) < 0.0005) { + shown = target; + vel = 0; + frame = 0; + paint(); + return; + } + vel = vel * 0.82 + d * 0.14; + shown += vel; + paint(); + frame = requestAnimationFrame(run); + }; + const update = () => { const r = wrap.getBoundingClientRect(); const vh = window.innerHeight; // p=0 gdy nagłówek mija środek widoku, p=1 przy końcu sekcji const p = reduce ? 1 : Math.min(Math.max((vh * 0.4 - r.top) / (r.height * 0.85), 0), 1); - line.style.strokeDashoffset = String(len * (1 - p)); - line2.style.strokeDashoffset = String(len2 * (1 - p)); - clip.setAttribute('width', String(p * 1000)); - clip2.setAttribute('width', String(p * 1000)); + if (reduce) { + shown = p; + paint(); + return; + } + target = p; + if (!frame) frame = requestAnimationFrame(run); }; + const onScroll = () => { cancelAnimationFrame(raf); raf = requestAnimationFrame(update); @@ -65,6 +98,7 @@ function ChartBackdrop() { window.addEventListener('resize', onScroll); return () => { cancelAnimationFrame(raf); + cancelAnimationFrame(frame); window.removeEventListener('scroll', onScroll); window.removeEventListener('resize', onScroll); }; @@ -76,7 +110,11 @@ function ChartBackdrop() { aria-hidden="true" className="pointer-events-none absolute inset-y-0 left-1/2 z-0 w-screen -translate-x-1/2" > - + @@ -87,17 +125,18 @@ function ChartBackdrop() { gradientUnits="userSpaceOnUse" x1="0" y1="660" - x2="206" - y2="1003" + x2="44" + y2="734" > + - + - + @@ -137,7 +176,7 @@ function ChartBackdrop() {