mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-15 10:38:19 +00:00
43 lines
961 B
JavaScript
43 lines
961 B
JavaScript
/*
|
|
* Scroll up Header
|
|
* Modified from https://codepen.io/sajjad/pen/vgEZNy
|
|
*/
|
|
|
|
// Hide header on scroll down
|
|
var didScroll;
|
|
var lastScrollTop = 0;
|
|
var delta = 5;
|
|
var navbarHeight = $('.mw-header-container').outerHeight();
|
|
|
|
$(window).scroll(function(event){
|
|
didScroll = true;
|
|
});
|
|
|
|
setInterval(function() {
|
|
if (didScroll) {
|
|
hasScrolled();
|
|
didScroll = false;
|
|
}
|
|
}, 250);
|
|
|
|
function hasScrolled() {
|
|
var st = $(this).scrollTop();
|
|
|
|
// Make scroll more than delta
|
|
if(Math.abs(lastScrollTop - st) <= delta)
|
|
return;
|
|
|
|
// If scrolled down and past the navbar, add class .nav-up.
|
|
if (st > lastScrollTop && st > navbarHeight){
|
|
// Scroll Down
|
|
$('header').removeClass('nav-down').addClass('nav-up');
|
|
} else {
|
|
// Scroll Up
|
|
if(st + $(window).height() < $(document).height()) {
|
|
$('header').removeClass('nav-up').addClass('nav-down');
|
|
}
|
|
}
|
|
|
|
lastScrollTop = st;
|
|
}
|