13 lines
390 B
TypeScript
13 lines
390 B
TypeScript
export function handleSmoothScrollToTitle(targetId: string): void {
|
|
const targetElement = document.querySelector(`#${targetId}`);
|
|
if (!targetElement) return;
|
|
|
|
const elementRect = targetElement.getBoundingClientRect();
|
|
const offset = 30; // 10px offset from top
|
|
|
|
window.scrollTo({
|
|
top: window.pageYOffset + elementRect.top - offset,
|
|
behavior: 'smooth',
|
|
});
|
|
}
|