Change animateToTop to this and add scroll-behavior: smooth;. It should do the work:
function animateToTop(e) { window.scrollTo(0, 0); } window.addEventListener('scroll', (e) => { var scrollTopBtn = document.getElementsByClassName('scrolimg')[0]; if (window.scrollY >= 100) { scrollTopBtn.style.visibility = 'visible'; } else { scrollTopBtn.style.visibility = 'hidden'; } }); html { scroll-behavior: smooth; } You can also use:
document.body.scrollTop = 0; document.documentElement.scrollTop = 0; But there's no more animation