Hide header when clicking on a footnote.
This commit is contained in:
parent
71b8e3576c
commit
22067e5d47
1 changed files with 11 additions and 0 deletions
|
|
@ -27,9 +27,15 @@ const header = document.getElementById('header');
|
||||||
const DWELL_TIME = 1500;
|
const DWELL_TIME = 1500;
|
||||||
let lastpos = window.scrollY;
|
let lastpos = window.scrollY;
|
||||||
let hideTimeout: NodeJS.Timeout;
|
let hideTimeout: NodeJS.Timeout;
|
||||||
|
let hideScroll = false;
|
||||||
function onScroll() {
|
function onScroll() {
|
||||||
const currentpos = window.scrollY;
|
const currentpos = window.scrollY;
|
||||||
clearTimeout(hideTimeout);
|
clearTimeout(hideTimeout);
|
||||||
|
if (hideScroll) {
|
||||||
|
header?.classList.add('-translate-y-full');
|
||||||
|
hideScroll = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (currentpos <= 100 || currentpos < lastpos) {
|
if (currentpos <= 100 || currentpos < lastpos) {
|
||||||
header?.classList.remove('-translate-y-full');
|
header?.classList.remove('-translate-y-full');
|
||||||
console.log("<", currentpos, lastpos);
|
console.log("<", currentpos, lastpos);
|
||||||
|
|
@ -43,6 +49,11 @@ function onScroll() {
|
||||||
}
|
}
|
||||||
lastpos = currentpos;
|
lastpos = currentpos;
|
||||||
}
|
}
|
||||||
|
document.querySelectorAll('sup > a').forEach((el) => {
|
||||||
|
el.addEventListener('click', () => {
|
||||||
|
hideScroll = true;
|
||||||
|
}, {passive: true});
|
||||||
|
});
|
||||||
header?.addEventListener('mouseenter', () => clearTimeout(hideTimeout));
|
header?.addEventListener('mouseenter', () => clearTimeout(hideTimeout));
|
||||||
header?.addEventListener('focusin', () => clearTimeout(hideTimeout));
|
header?.addEventListener('focusin', () => clearTimeout(hideTimeout));
|
||||||
window.addEventListener('scroll', onScroll, {passive: true});
|
window.addEventListener('scroll', onScroll, {passive: true});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue