Skip to content

Commit b5b9cc0

Browse files
Scroll to top code Added Back
1 parent cc56bc1 commit b5b9cc0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

script.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,18 @@ const sampleProjects = [
423423
grabCursor: true,
424424
speed: 600,
425425
});
426-
426+
//Scroll to top button functionality
427+
const scrollToTopBtn = document.getElementById("scrollToTopBtn");
428+
429+
// Show button when user scrolls down
430+
window.addEventListener("scroll", () => {
431+
scrollToTopBtn.style.display = window.scrollY > 300 ? "block" : "none";
432+
});
433+
434+
// Scroll to top smoothly
435+
scrollToTopBtn.addEventListener("click", () => {
436+
window.scrollTo({
437+
top: 0,
438+
behavior: "smooth"
439+
});
440+
});

0 commit comments

Comments
 (0)