A client-side hook that enables smooth scrolling behavior for anchor links with an automatic offset adjustment.
import SmoothScroll from '@/hooks/smooth-scroll'export default function Layout() {return (<><SmoothScroll />{/* Your content */}</>)}
a[href^="#"])no-anchor-scroll class to specific links#scrollingDirection to 'down' and locks it via lockScrollDirectionscrollend eventTo exclude specific links from smooth scrolling, add the no-anchor-scroll class:
<ahref="#section"className="no-anchor-scroll">Jump without smooth scroll</a>
When an anchor link is clicked, the hook:
state.scrollingDirection to 'down'state.lockScrollDirection to trueThis prevents the sticky navbar from appearing during smooth scroll (since it only shows when direction is 'up'). The lock is released when the scrollend event fires, restoring normal scroll direction detection.
The component is used in src/app/layout.tsx to enable smooth scrolling throughout the application.