-
Notifications
You must be signed in to change notification settings - Fork 5
/
topbar.js
51 lines (44 loc) · 1.48 KB
/
topbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$(function() {
/*
* Hide Header on scroll down
*/
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();
function hasScrolled() {
var st = $(this).scrollTop();
/* Make sure they scroll more than delta */
if (Math.abs(lastScrollTop - st) <= delta) {
return;
}
if (st > lastScrollTop && st > topbarHeight) {
/* Scroll Down */
topbarWrapper.removeClass("topbar-down").addClass("topbar-up");
if (toc.length > 0) { toc.removeClass("topbar-down");}
if (access.length > 0) { access.removeClass("topbar-down");}
if (searchInput.is(":focus")) { searchInput.blur(); }/* remove focus */
} else if (st + $(window).height() < $(document).height()) {
/* Scroll Up */
topbarWrapper.removeClass("topbar-up").addClass("topbar-down");
if (toc.length > 0) { toc.addClass("topbar-down");}
if (access.length > 0) {access.addClass("topbar-down");}
}
lastScrollTop = st;
}
$(window).scroll(function(event) {
if ($("#topbar-title").is(":hidden")) { /* Not in small screens */
didScroll = true;
}
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
});