add
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
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);
|
||||
};
|
||||
}, []);
|
||||
};
|
Reference in New Issue
Block a user