100-project-100-days-website/100_projects/20-scroll-to-top-button/main.js

12 lines
268 B
JavaScript
Raw Normal View History

2023-03-13 17:14:17 +03:00
let span = document.querySelector(".up");
window.onscroll = function () {
this.scrollY >= 1000 ? span.classList.add("show") : span.classList.remove("show");
};
span.onclick = function () {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};