Web: gradient niebieski plynnie rozplywa sie w tle, animacja wykresu na sprezynie (lag+bounce)
This commit is contained in:
@@ -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"
|
||||
>
|
||||
<svg viewBox="0 0 1000 700" preserveAspectRatio="none" className="h-full w-full">
|
||||
<svg
|
||||
viewBox="0 0 1000 700"
|
||||
preserveAspectRatio="none"
|
||||
className="h-full w-full overflow-visible"
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id="chart-fill" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stopColor="var(--accent)" stopOpacity="0.5" />
|
||||
@@ -87,17 +125,18 @@ function ChartBackdrop() {
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="0"
|
||||
y1="660"
|
||||
x2="206"
|
||||
y2="1003"
|
||||
x2="44"
|
||||
y2="734"
|
||||
>
|
||||
<stop offset="0%" stopColor="var(--chart-blue)" stopOpacity="0.4" />
|
||||
<stop offset="35%" stopColor="var(--chart-blue)" stopOpacity="0.08" />
|
||||
<stop offset="100%" stopColor="var(--chart-blue)" stopOpacity="0" />
|
||||
</linearGradient>
|
||||
<clipPath id="chart-reveal">
|
||||
<rect ref={clipRef} x="0" y="0" width="0" height="700" />
|
||||
<rect ref={clipRef} x="0" y="0" width="0" height="950" />
|
||||
</clipPath>
|
||||
<clipPath id="chart-reveal-2">
|
||||
<rect ref={clip2Ref} x="0" y="0" width="0" height="700" />
|
||||
<rect ref={clip2Ref} x="0" y="0" width="0" height="950" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g clipPath="url(#chart-reveal)">
|
||||
@@ -137,7 +176,7 @@ function ChartBackdrop() {
|
||||
</g>
|
||||
<g clipPath="url(#chart-reveal-2)">
|
||||
<path
|
||||
d={`${CHART_PATH2} L1000,700 L0,700 Z`}
|
||||
d={`${CHART_PATH2} L1000,900 L0,900 Z`}
|
||||
fill="url(#chart-fill-2)"
|
||||
fillOpacity="0.3"
|
||||
stroke="none"
|
||||
|
||||
Reference in New Issue
Block a user