59 lines
No EOL
1.8 KiB
JavaScript
59 lines
No EOL
1.8 KiB
JavaScript
|
|
|
|
export function progressBar(){
|
|
const bar = document.getElementById('progressBar');
|
|
if (!bar) return;
|
|
|
|
window.addEventListener('scroll', () => {
|
|
const scrollTop = window.scrollY;
|
|
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
|
|
const progress = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0;
|
|
bar.style.width = `${progress}vw`;
|
|
}, { passive: true });
|
|
}
|
|
|
|
|
|
export function scrollBack(){
|
|
const bottomBar = document.getElementById('bottom-bar');
|
|
const navInvestigation = document.getElementById('nav-investigation');
|
|
const header = document.getElementById('site-header');
|
|
const footerEl = document.getElementById('support-bar') || document.getElementById('site-footer');
|
|
|
|
let lastY = window.scrollY;
|
|
let peakY = window.scrollY;
|
|
let visible = false;
|
|
|
|
window.addEventListener('scroll', () => {
|
|
const currentY = window.scrollY;
|
|
|
|
// header : basé uniquement sur la position absolue
|
|
if (navInvestigation && header) {
|
|
header.classList.toggle('has-nav-investigation', currentY >= 160);
|
|
}
|
|
|
|
// zone footer : bottom-bar masquée et verrouillée
|
|
const inFooterZone = footerEl && (currentY + window.innerHeight >= footerEl.offsetTop);
|
|
|
|
if (inFooterZone) {
|
|
if (visible) {
|
|
visible = false;
|
|
if (bottomBar) bottomBar.classList.remove('is-visible');
|
|
}
|
|
} else if (currentY > lastY) {
|
|
// scroll bas
|
|
peakY = currentY;
|
|
if (!visible && currentY > 280) {
|
|
visible = true;
|
|
if (bottomBar) bottomBar.classList.add('is-visible');
|
|
}
|
|
} else {
|
|
// scroll haut : hide après 200px remontés
|
|
if (visible && peakY - currentY >= 200) {
|
|
visible = false;
|
|
if (bottomBar) bottomBar.classList.remove('is-visible');
|
|
}
|
|
}
|
|
|
|
lastY = currentY;
|
|
}, { passive: true });
|
|
} |