Skip to content

Commit 42164b2

Browse files
authored
Merge pull request #14 from maitamdev/feat/scroll-utils
feat(utils): add scroll utilities
2 parents e2c7806 + 043cd27 commit 42164b2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/utils/scrollUtils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Scroll utility functions
2+
export function scrollToElement(id: string, offset: number = 80): void {
3+
const el = document.getElementById(id);
4+
if (el) { const y = el.getBoundingClientRect().top + window.scrollY - offset; window.scrollTo({ top: y, behavior: 'smooth' }); }
5+
}
6+
7+
export function lockScroll(): () => void {
8+
const scrollY = window.scrollY;
9+
document.body.style.position = 'fixed';
10+
document.body.style.top = '-' + scrollY + 'px';
11+
document.body.style.width = '100%';
12+
return () => { document.body.style.position = ''; document.body.style.top = ''; document.body.style.width = ''; window.scrollTo(0, scrollY); };
13+
}
14+

0 commit comments

Comments
 (0)