const x = 100; // or any values const y = 50; // or any values const scrollToTop = () => window.scrollTo(x, y);
In addition to that, you can also set to have a smooth scrolling animation by adding the "smooth" behavior option.
const scrollToTop = () => window.scrollTo({ top: 100, behavior: 'smooth' });
Leave a reply