schon/storefront/app/composables/scrollTo/useScrollTo.ts
2026-02-27 21:59:51 +03:00

34 lines
542 B
TypeScript

export function useScrollTo() {
const router = useRouter();
function scroll(id: string) {
const element = document.getElementById(id);
if (element) {
element.scrollIntoView({
behavior: 'smooth',
});
} else {
console.error('Element not found:', id);
}
}
function scrollTo(id: string, routePath?: string) {
if (routePath) {
router
.push({
path: routePath,
})
.then(() => {
scroll(id);
});
} else {
setTimeout(() => {
scroll(id);
}, 100);
}
}
return {
scrollTo,
};
}