Skip to content

Commit

Permalink
dashboard changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankush-ai committed May 10, 2024
1 parent 02b6aa5 commit 31bfc85
Showing 1 changed file with 15 additions and 39 deletions.
54 changes: 15 additions & 39 deletions dashbboard.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
document.addEventListener("DOMContentLoaded", function() {
// Cache the back-to-top button element
// Back-Top Button
document.addEventListener("scroll", function() {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const backToTopButton = document.querySelector(".back-to-top");

// Function to scroll to the top with smooth behavior
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
// show/hide back to top button based on scroll position
if (scrollTop > 50) {
document.body.classList.add("scroll-down");
} else {
document.body.classList.remove("scroll-down");
}

// Function to handle scroll event with throttling
function handleScroll() {
const scrollTop = window.scrollY || document.documentElement.scrollTop;
if (scrollTop > 50) {
backToTopButton.classList.add("visible");
} else {
backToTopButton.classList.remove("visible");
}
}

// Throttle the scroll event listener
let throttleTimeout;
function throttleScroll() {
if (!throttleTimeout) {
throttleTimeout = setTimeout(function() {
throttleTimeout = null;
handleScroll();
}, 200); // Adjust the throttle interval as needed
}
}

// Event listener for scrolling
window.addEventListener("scroll", throttleScroll);

// Event listener for clicking back-to-top button
backToTopButton.addEventListener("click", function() {
scrollToTop();
// Add focus to an element after scrolling to improve accessibility
document.querySelector("h1").focus(); // Example: focus on the page heading
});
});

// Function to scroll to the top when the button is clicked
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
}

0 comments on commit 31bfc85

Please sign in to comment.