2019-08-15 17:40:13 +00:00
|
|
|
/*
|
2019-10-08 19:22:02 +00:00
|
|
|
* Scroll up Header
|
|
|
|
* Modified from https://codepen.io/sajjad/pen/vgEZNy
|
|
|
|
*/
|
2019-08-15 17:40:13 +00:00
|
|
|
|
2019-12-26 09:40:43 +00:00
|
|
|
( function () {
|
2019-12-25 23:23:38 +00:00
|
|
|
// Hide header on scroll down
|
2019-12-26 09:40:43 +00:00
|
|
|
let didScroll,
|
|
|
|
lastScrollTop = 0,
|
|
|
|
navbarHeight = 0;
|
|
|
|
const delta = 0,
|
|
|
|
header = document.getElementsByTagName( 'header' )[ 0 ],
|
|
|
|
headerContainer = document.querySelector( '.mw-header-container' );
|
|
|
|
if ( headerContainer !== null ) {
|
2019-12-25 23:23:38 +00:00
|
|
|
navbarHeight = headerContainer.offsetHeight;
|
|
|
|
}
|
|
|
|
|
2019-12-26 09:40:43 +00:00
|
|
|
window.addEventListener( 'scroll', () => {
|
2019-12-25 23:23:38 +00:00
|
|
|
didScroll = true;
|
2019-12-26 09:40:43 +00:00
|
|
|
} );
|
2019-12-25 23:23:38 +00:00
|
|
|
|
|
|
|
function hasScrolled() {
|
|
|
|
const st = window.scrollY;
|
|
|
|
|
|
|
|
// Make scroll more than delta
|
2019-12-26 09:40:43 +00:00
|
|
|
if ( Math.abs( lastScrollTop - st ) <= delta ) {
|
2019-12-25 23:23:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-26 09:40:43 +00:00
|
|
|
if ( st > lastScrollTop && st > navbarHeight ) {
|
2019-12-25 23:23:38 +00:00
|
|
|
// If scrolled down and past the navbar, add class .nav-up.
|
|
|
|
// Scroll Down
|
2019-12-26 09:40:43 +00:00
|
|
|
header.classList.remove( 'nav-down' );
|
|
|
|
header.classList.add( 'nav-up' );
|
2019-12-25 23:23:38 +00:00
|
|
|
} else {
|
|
|
|
// Scroll Up
|
2019-12-26 09:40:43 +00:00
|
|
|
const body = document.body,
|
|
|
|
html = document.documentElement,
|
2019-12-25 23:23:38 +00:00
|
|
|
|
2019-12-26 09:40:43 +00:00
|
|
|
documentHeight = Math.max( body.scrollHeight, body.offsetHeight,
|
|
|
|
html.clientHeight, html.scrollHeight, html.offsetHeight );
|
2019-12-25 23:23:38 +00:00
|
|
|
|
2019-12-26 09:40:43 +00:00
|
|
|
if ( st + window.innerHeight < documentHeight ) {
|
|
|
|
header.classList.remove( 'nav-up' );
|
|
|
|
header.classList.add( 'nav-down' );
|
2019-12-25 23:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastScrollTop = st;
|
|
|
|
}
|
2019-12-26 09:40:43 +00:00
|
|
|
|
|
|
|
setInterval( function () {
|
|
|
|
if ( didScroll ) {
|
|
|
|
hasScrolled();
|
|
|
|
didScroll = false;
|
|
|
|
}
|
|
|
|
}, 250 );
|
|
|
|
}() );
|