update code and styles

This commit is contained in:
2026-06-03 19:19:56 +05:30
parent 6eea5636fb
commit 4ba08fc400
21 changed files with 939 additions and 593 deletions

View File

@@ -33,7 +33,29 @@ export default function SmoothScroll() {
// Mouse/desktop only — touch devices already have good native momentum.
const isPointerFine = window.matchMedia("(hover: hover) and (pointer: fine)").matches;
if (routeDisabled || prefersReduced || !isPointerFine) return;
let hashTimer: ReturnType<typeof setTimeout>;
if (routeDisabled || prefersReduced || !isPointerFine) {
if (!window.location.hash) {
window.scrollTo(0, 0);
} else {
const scrollToHash = () => {
try {
const target = document.querySelector(window.location.hash) as HTMLElement | null;
if (target) {
target.scrollIntoView();
}
} catch (err) {
console.warn(err);
}
};
scrollToHash();
hashTimer = setTimeout(scrollToHash, 100);
}
return () => {
if (hashTimer) clearTimeout(hashTimer);
};
}
gsap.registerPlugin(ScrollTrigger);
@@ -45,6 +67,24 @@ export default function SmoothScroll() {
smoothWheel: true,
});
if (!window.location.hash) {
lenis.scrollTo(0, { immediate: true });
window.scrollTo(0, 0);
} else {
const scrollToHash = () => {
try {
const target = document.querySelector(window.location.hash) as HTMLElement | null;
if (target) {
lenis.scrollTo(target, { immediate: true });
}
} catch (err) {
console.warn(err);
}
};
scrollToHash();
hashTimer = setTimeout(scrollToHash, 100);
}
lenis.on("scroll", ScrollTrigger.update);
const tickerCb = (time: number) => lenis.raf(time * 1000); // ticker is seconds, Lenis wants ms
gsap.ticker.add(tickerCb);
@@ -52,6 +92,7 @@ export default function SmoothScroll() {
ScrollTrigger.refresh();
return () => {
if (hashTimer) clearTimeout(hashTimer);
gsap.ticker.remove(tickerCb);
lenis.destroy();
};