Skip to content

Commit

Permalink
Enhance site header visibility control on TOC link click
Browse files Browse the repository at this point in the history
  • Loading branch information
Deep0Thinking committed Jan 22, 2024
1 parent 630b2f4 commit 9b8bab1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions assets/js/custom-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,31 @@ for (var i = 0, len = x.length; i < len; i++) {
// Dynamic visibility for sticky header based on scroll direction

let lastScrollTop = 0; // This variable will hold the last scroll position
let isTocClicked = false; // Flag to track if a toc-entry link was clicked

window.addEventListener("scroll", function () {
let currentScroll = window.pageYOffset || document.documentElement.scrollTop;

if (currentScroll > lastScrollTop) {
// Scrolling down
if (isTocClicked) {
// If a toc-entry was clicked, hide the site header
document.querySelector('.site-header').classList.add('hide-site-header');
isTocClicked = false; // Reset the flag
} else {
// Scrolling up
document.querySelector('.site-header').classList.remove('hide-site-header');
if (currentScroll > lastScrollTop) {
// Scrolling down
document.querySelector('.site-header').classList.add('hide-site-header');
} else if (currentScroll < lastScrollTop) {
// Scrolling up
document.querySelector('.site-header').classList.remove('hide-site-header');
}
}
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // For Mobile or negative scrolling
}, false);
}, false);

// Modify event listener for toc-entry hyperlinks
document.querySelectorAll('.toc-entry').forEach(function (element) {
element.addEventListener('click', function () {
// Set the flag when a toc-entry is clicked
isTocClicked = true;
});
});

0 comments on commit 9b8bab1

Please sign in to comment.