Skip to content

Commit

Permalink
Merge pull request #1097 from ygowthamr/main
Browse files Browse the repository at this point in the history
Enhanced ScrollTop Button Functionality
  • Loading branch information
vivekvardhan2810 authored Oct 29, 2024
2 parents b7d4898 + 6ffea9b commit 063d4aa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions script/scroll.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const scrollTopBtn = document.getElementById("scrollTopBtn");
scrollTopBtn.style.setProperty('visibility', 'hidden', 'important');

window.onscroll = function() {
const scrollTopBtn = document.getElementById("scrollTopBtn");
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
scrollTopBtn.style.display = "block";
window.addEventListener('scroll', function() {

if (window.scrollY > 100) {
scrollTopBtn.style.setProperty('visibility', 'visible', 'important');
} else {
scrollTopBtn.style.display = "none";
scrollTopBtn.style.setProperty('visibility', 'hidden', 'important');
}
};
});

function scrollToTop() {
window.scrollTo({top: 0, behavior: 'smooth'});
Expand Down

0 comments on commit 063d4aa

Please sign in to comment.