2019-09-30 15:38:41 +03:00
|
|
|
/*
|
|
|
|
* Hide Header on scroll down
|
2020-01-02 16:17:49 +03:00
|
|
|
* v2.0
|
|
|
|
* https://github.com/cotes2020/jekyll-theme-chirpy
|
2019-09-30 15:38:41 +03:00
|
|
|
* © 2018-2019 Cotes Chung
|
|
|
|
* MIT License
|
|
|
|
*/
|
2020-05-29 19:48:10 +03:00
|
|
|
|
2019-09-30 15:38:41 +03:00
|
|
|
$(function() {
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
const topbarWrapper = $("#topbar-wrapper");
|
|
|
|
const toc = $("#toc-wrapper");
|
|
|
|
const access = $(".access");
|
|
|
|
const searchInput = $("#search-input");
|
|
|
|
|
|
|
|
let didScroll;
|
|
|
|
let lastScrollTop = 0;
|
|
|
|
|
|
|
|
const delta = 5;
|
|
|
|
const topbarHeight = topbarWrapper.outerHeight();
|
2019-09-30 15:38:41 +03:00
|
|
|
|
|
|
|
function hasScrolled() {
|
|
|
|
var st = $(this).scrollTop();
|
|
|
|
|
2020-05-29 19:48:10 +03:00
|
|
|
/* Make sure they scroll more than delta */
|
2020-08-19 07:26:45 +03:00
|
|
|
if (Math.abs(lastScrollTop - st) <= delta) {
|
2019-09-30 15:38:41 +03:00
|
|
|
return;
|
2020-08-19 07:26:45 +03:00
|
|
|
}
|
2019-09-30 15:38:41 +03:00
|
|
|
|
|
|
|
if (st > lastScrollTop && st > topbarHeight) {
|
2020-05-29 19:48:10 +03:00
|
|
|
/* Scroll Down */
|
2021-01-23 10:07:18 +03:00
|
|
|
topbarWrapper.removeClass("topbar-down").addClass("topbar-up");
|
2019-09-30 15:38:41 +03:00
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
if (toc.length > 0) {
|
|
|
|
toc.removeClass("topbar-down");
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
if (access.length > 0) {
|
|
|
|
access.removeClass("topbar-down");
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
if (searchInput.is(":focus")) {
|
|
|
|
searchInput.blur(); /* remove focus */
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
} else if (st + $(window).height() < $(document).height()) {
|
2020-05-29 19:48:10 +03:00
|
|
|
/* Scroll Up */
|
2021-01-23 10:07:18 +03:00
|
|
|
topbarWrapper.removeClass("topbar-up").addClass("topbar-down");
|
|
|
|
if (toc.length > 0) {
|
|
|
|
toc.addClass("topbar-down");
|
|
|
|
}
|
|
|
|
if (access.length > 0) {
|
|
|
|
access.addClass("topbar-down");
|
2019-09-30 15:38:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastScrollTop = st;
|
|
|
|
}
|
2020-08-19 07:26:45 +03:00
|
|
|
|
|
|
|
$(window).scroll(function(event) {
|
|
|
|
if ($("#topbar-title").is(":hidden")) { /* Not in small screens */
|
|
|
|
didScroll = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
setInterval(function() {
|
|
|
|
if (didScroll) {
|
|
|
|
hasScrolled();
|
|
|
|
didScroll = false;
|
|
|
|
}
|
|
|
|
}, 250);
|
|
|
|
|
2021-01-23 10:07:18 +03:00
|
|
|
});
|