Web: paralaksa w sekcji System gotowy - hook useParallax wyprowadzony do lib

This commit is contained in:
tisachi
2026-10-20 01:35:33 +02:00
parent 71221ca7f1
commit 45cb4a33b0
3 changed files with 110 additions and 68 deletions

View File

@@ -0,0 +1,43 @@
import { useEffect, type RefObject } from 'react';
/**
* Tło z paralaksą — elementy `data-parallax` przesuwają się względem środka
* widoku o przeskalowany współczynnik. W reduced-motion statycznie.
*/
export function useParallax(rootRef: RefObject<HTMLDivElement | null>) {
useEffect(() => {
const root = rootRef.current;
if (!root) return;
if (
typeof window.matchMedia === 'function' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches
)
return;
const layers = Array.from(root.querySelectorAll<HTMLElement>('[data-parallax]'));
if (!layers.length) return;
let raf = 0;
const update = () => {
const rect = root.getBoundingClientRect();
for (const layer of layers) {
const speed = Number(layer.dataset.parallax) || 0;
const offset = (rect.top + rect.height / 2 - window.innerHeight / 2) * speed;
layer.style.transform = `translate3d(0, ${offset.toFixed(1)}px, 0)`;
}
};
const onScroll = () => {
cancelAnimationFrame(raf);
raf = requestAnimationFrame(update);
};
update();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onScroll);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener('scroll', onScroll);
window.removeEventListener('resize', onScroll);
};
}, [rootRef]);
}

View File

@@ -1,34 +1,74 @@
import { useRef } from 'react';
import { ArrowRight, ShieldCheck } from 'lucide-react';
import { Reveal } from '../components/Reveal';
import { adminUrl, appUrl } from '../lib/links';
import { useParallax } from '../lib/useParallax';
import { Section } from './shared';
/** CTA końcowa: „uruchom system”. */
const LINES_A = [
'gotowe: trening · coaching · siłownie',
'błędy krytyczne: brak',
'dane: Twoja infrastruktura',
'start gotowy — wybieraj modul',
];
const LINES_B = ['$ fitos --run', 'port 9002 · self-hosted', '$ ./start --wybierz-modul'];
/** CTA końcowa: „uruchom system” — czarne tło z paralaksą logu startowego. */
export function Cta() {
const rootRef = useRef<HTMLDivElement>(null);
useParallax(rootRef);
return (
<Section id="start">
<Reveal className="mx-auto max-w-3xl text-center">
<p className="font-mono text-xs tracking-widest text-accent">$ fitos --run</p>
<h2 className="mt-3 text-3xl font-bold text-ink sm:text-4xl">System gotowy.</h2>
<p className="mt-3 text-[15px] leading-relaxed text-dim">
Włącz moduł, którego potrzebujesz: trening swój albo trening podopiecznych.
</p>
<div className="mt-7 flex flex-wrap items-center justify-center gap-3">
<a
href={appUrl()}
className="inline-flex items-center gap-2 rounded-lg border-0 bg-(image:--btn-grad) px-5 py-2.5 text-sm font-bold text-accent-ink shadow-(--btn-shadow) transition-transform hover:-translate-y-px"
>
Otwórz aplikację <ArrowRight size={16} aria-hidden="true" />
</a>
<a
href={adminUrl()}
className="inline-flex items-center gap-2 rounded-lg border border-line bg-card px-5 py-2.5 text-sm font-semibold text-ink transition-colors hover:border-accent/50"
>
<ShieldCheck size={16} aria-hidden="true" className="text-accent" />
Panel admina
</a>
</div>
</Reveal>
</Section>
<div ref={rootRef} className="relative overflow-hidden border-y border-line bg-terminal">
<div
aria-hidden="true"
className="pointer-events-none absolute inset-x-0 -top-8 left-[5%] flex flex-col gap-1 font-mono text-[13px] leading-7 whitespace-nowrap text-dim/10 select-none"
data-parallax="0.28"
>
{[...LINES_A, ...LINES_A].map((l, i) => (
<span key={i}>{l}</span>
))}
</div>
<div
aria-hidden="true"
className="pointer-events-none absolute inset-x-0 -bottom-8 right-[5%] flex flex-col items-end gap-1 font-mono text-[13px] leading-7 whitespace-nowrap text-dim/10 select-none"
data-parallax="-0.18"
>
{[...LINES_B, ...LINES_B].map((l, i) => (
<span key={i}>{l}</span>
))}
</div>
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 bg-(image:--ambient)"
data-parallax="0.06"
/>
<Section id="start" className="relative">
<Reveal className="mx-auto max-w-3xl text-center">
<p className="font-mono text-xs tracking-widest text-accent">$ fitos --run</p>
<h2 className="mt-3 text-3xl font-bold text-ink sm:text-4xl">System gotowy.</h2>
<p className="mt-3 text-[15px] leading-relaxed text-dim">
Włącz moduł, którego potrzebujesz: trening swój albo trening podopiecznych.
</p>
<div className="mt-7 flex flex-wrap items-center justify-center gap-3">
<a
href={appUrl()}
className="inline-flex items-center gap-2 rounded-lg border-0 bg-(image:--btn-grad) px-5 py-2.5 text-sm font-bold text-accent-ink shadow-(--btn-shadow) transition-transform hover:-translate-y-px"
>
Otwórz aplikację <ArrowRight size={16} aria-hidden="true" />
</a>
<a
href={adminUrl()}
className="inline-flex items-center gap-2 rounded-lg border border-line bg-card px-5 py-2.5 text-sm font-semibold text-ink transition-colors hover:border-accent/50"
>
<ShieldCheck size={16} aria-hidden="true" className="text-accent" />
Panel admina
</a>
</div>
</Reveal>
</Section>
</div>
);
}

View File

@@ -1,47 +1,6 @@
import { useEffect, useRef } from 'react';
import { useRef } from 'react';
import { Reveal } from '../components/Reveal';
/**
* Tło z paralaksą — elementy przesuwają się względem widoku inną prędkością
* (dane `data-parallax` = przeskalowany współczynnik). W reduced-motion statycznie.
*/
function useParallax(rootRef: React.RefObject<HTMLDivElement | null>) {
useEffect(() => {
const root = rootRef.current;
if (!root) return;
if (
typeof window.matchMedia === 'function' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches
)
return;
const layers = Array.from(root.querySelectorAll<HTMLElement>('[data-parallax]'));
if (!layers.length) return;
let raf = 0;
const update = () => {
const rect = root.getBoundingClientRect();
for (const layer of layers) {
const speed = Number(layer.dataset.parallax) || 0;
const offset = (rect.top + rect.height / 2 - window.innerHeight / 2) * speed;
layer.style.transform = `translate3d(0, ${offset.toFixed(1)}px, 0)`;
}
};
const onScroll = () => {
cancelAnimationFrame(raf);
raf = requestAnimationFrame(update);
};
update();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onScroll);
return () => {
cancelAnimationFrame(raf);
window.removeEventListener('scroll', onScroll);
window.removeEventListener('resize', onScroll);
};
}, [rootRef]);
}
import { useParallax } from '../lib/useParallax';
const LINES_A = [
'$ fitos --run',