- Scroll to Top
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
Usage:
scrollToTop();
- Scroll to Element Smoothly
function scrollToElement(element) {
element.scrollIntoView({ behavior: 'smooth' });
}
Usage:
const myElement = document.getElementById('myElement');
scrollToElement(myElement);
Top comments (0)