29 lines
794 B
TypeScript
29 lines
794 B
TypeScript
import { gsap } from "gsap";
|
|
import { ScrollTrigger } from "gsap/ScrollTrigger";
|
|
import { ScrollToPlugin } from "gsap/ScrollToPlugin";
|
|
|
|
gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);
|
|
|
|
export { gsap, ScrollTrigger };
|
|
|
|
export const prefersReducedMotion = (): boolean =>
|
|
typeof window !== "undefined" &&
|
|
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
|
|
/** Défilement fluide vers une section, sans toucher à l'URL. */
|
|
export const scrollToSection = (hash: string): void => {
|
|
const target = document.querySelector<HTMLElement>(hash);
|
|
if (!target) return;
|
|
|
|
if (prefersReducedMotion()) {
|
|
target.scrollIntoView({ behavior: "auto" });
|
|
return;
|
|
}
|
|
|
|
gsap.to(window, {
|
|
duration: 1,
|
|
scrollTo: { y: target, offsetY: 96 },
|
|
ease: "power3.inOut",
|
|
});
|
|
};
|