Skip to content

Commit

Permalink
Merge pull request #338 from ygowthamr/scrollBtnIssue
Browse files Browse the repository at this point in the history
Enhanced ScrollTop Button Functionality
  • Loading branch information
Harshdev098 authored Oct 30, 2024
2 parents 11a377f + 9bd3249 commit 1da6fe3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
24 changes: 11 additions & 13 deletions public/script/main-page-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ function hide() {
document.getElementById("secondicon").style.display = "none";
}

let scrollToTopButton = document.getElementById("scrollToTop");
const scrollTopBtn = document.getElementById("scrollToTop");
scrollTopBtn.style.setProperty('visibility', 'hidden', 'important');

// Show the button when the user scrolls down 100px from the top
window.onscroll = function () {
if (
document.body.scrollTop > 100 ||
document.documentElement.scrollTop > 100
) {
scrollToTopButton.style.display = "block";
} else {
scrollToTopButton.style.display = "none";
}
};
window.addEventListener('scroll', function() {

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

// Scroll to the top when the button is clicked
scrollToTopButton.addEventListener("click", function () {
scrollTopBtn.addEventListener("click", function () {
window.scrollTo({
top: 0,
behavior: "smooth",
Expand Down
26 changes: 12 additions & 14 deletions public/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,20 @@ const last2 = document.querySelectorAll(".last_img_animation2");
last2.forEach((el) => observer8.observe(el));

// Get the button
let scrollToTopButton = document.getElementById("scrollToTop");

// Show the button when the user scrolls down 100px from the top
window.onscroll = function () {
if (
document.body.scrollTop > 100 ||
document.documentElement.scrollTop > 100
) {
scrollToTopButton.style.display = "block";
} else {
scrollToTopButton.style.display = "none";
}
};
const scrollTopBtn = document.getElementById("scrollToTop");
scrollTopBtn.style.setProperty('visibility', 'hidden', 'important');

window.addEventListener('scroll', function() {

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

// Scroll to the top when the button is clicked
scrollToTopButton.addEventListener("click", function () {
scrollTopBtn.addEventListener("click", function () {
window.scrollTo({
top: 0,
behavior: "smooth",
Expand Down
24 changes: 11 additions & 13 deletions public/script/stk_mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,20 @@ const set = async () => {
}
};

let scrollToTopButton = document.getElementById("scrollToTop");
const scrollTopBtn = document.getElementById("scrollToTop");
scrollTopBtn.style.setProperty('visibility', 'hidden', 'important');

// Show the button when the user scrolls down 100px from the top
window.onscroll = function () {
if (
document.body.scrollTop > 100 ||
document.documentElement.scrollTop > 100
) {
scrollToTopButton.style.display = "block";
} else {
scrollToTopButton.style.display = "none";
}
};
window.addEventListener('scroll', function() {

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

// Scroll to the top when the button is clicked
scrollToTopButton.addEventListener("click", function () {
scrollTopBtn.addEventListener("click", function () {
window.scrollTo({
top: 0,
behavior: "smooth",
Expand Down

0 comments on commit 1da6fe3

Please sign in to comment.