Skip to content

Commit

Permalink
Create script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
majiday authored Jun 10, 2024
1 parent bd2fd3d commit 976ad52
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Show "Back to Top" button when user scrolls down
window.addEventListener('scroll', function() {
const backToTopButton = document.getElementById('back-to-top');
if (window.scrollY > 200) {
backToTopButton.style.display = 'block';
} else {
backToTopButton.style.display = 'none';
}
});

// Scroll to top when "Back to Top" button is clicked
document.getElementById('back-to-top').addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});

0 comments on commit 976ad52

Please sign in to comment.