I think the simplest solution is:
window.scrollTo({top: 0, behavior: 'smooth'});
If you wanted instant scrolling then just use:
window.scrollTo({top: 0});
Can be used as a function:
// Scroll To Top
function scrollToTop() {
window.scrollTo({top: 0, behavior: 'smooth'});
}
Or as an onclick handler:
<button onclick='window.scrollTo({top: 0, behavior: "smooth"});'>Scroll to Top</button>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…