This commit is contained in:
2025-09-17 15:35:06 +02:00
parent f712a6c894
commit 8f997b2f86
5 changed files with 48 additions and 11 deletions

View File

@@ -0,0 +1,28 @@
import { useEffect } from 'react';
export const useSmoothScroll = () => {
useEffect(() => {
const handleLinkClick = (e: MouseEvent) => {
const target = e.target as HTMLAnchorElement;
const href = target.getAttribute('href');
if (href && href.startsWith('#')) {
e.preventDefault();
const targetId = href.substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
});
}
}
};
document.addEventListener('click', handleLinkClick);
return () => {
document.removeEventListener('click', handleLinkClick);
};
}, []);
};