Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions src/pages/products/Manuals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,19 @@ export default function Landing() {
const container = document.getElementById('landing-container');
if (!container) return;

let ticking = false;
let rafId: number | null = null;

const handleScroll = () => {
if (!ticking) {
window.requestAnimationFrame(() => {
const scrollTop = container.scrollTop;

setScrollY((prev) => {
// Optimization: Stop updating state once the hero section is fully hidden (opacity reaches 0 at 600px).
// This prevents unnecessary re-renders when scrolling through the rest of the page.
if (prev > 600 && scrollTop > 600) {
return prev;
}
return scrollTop;
});

ticking = false;
});
ticking = true;
}
};

container.addEventListener('scroll', handleScroll, { passive: true });
return () => container.removeEventListener('scroll', handleScroll);
}, []);
const update = () => {
const scrollTop = container.scrollTop;

// Optimization: Stop updating once the hero section is fully hidden (opacity reaches 0 at 600px).
// This prevents unnecessary updates when scrolling through the rest of the page.
if (scrollTop > 600) {
ticking.current = false;
rafId = null;
return;
}

const heroOpacity = Math.max(0, 1 - scrollTop / 600);
const heroScale = 1 + scrollTop * 0.0002;

Expand All @@ -83,11 +68,12 @@ export default function Landing() {
}

ticking.current = false;
rafId = null;
};

const handleScroll = () => {
if (!ticking.current) {
window.requestAnimationFrame(update);
rafId = window.requestAnimationFrame(update);
ticking.current = true;
}
};
Expand All @@ -96,7 +82,12 @@ export default function Landing() {
update();

container.addEventListener('scroll', handleScroll, { passive: true });
return () => container.removeEventListener('scroll', handleScroll);
return () => {
container.removeEventListener('scroll', handleScroll);
if (rafId !== null) {
cancelAnimationFrame(rafId);
}
};
}, []);

return (
Expand Down