-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsup-topbar.js
executable file
·42 lines (32 loc) · 994 Bytes
/
sup-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
// ---------------------------------------------------------------
// SlideUpTopBar for Foundation top-bar
// ---------------------------------------------------------------
var $window = $(window);
var didScroll;
var lastScrollTop = 0;
var scrollAmount = 10; // Value of scroll amount
var navbarHeight = $('.slideUp').outerHeight();
$(window).scroll(function(event){
didScroll = true;
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
"use strict";
var sup = $(window).scrollTop();
if(Math.abs(lastScrollTop - sup) <= scrollAmount) return;
if (sup > lastScrollTop && sup > navbarHeight){
// On Scroll Down
$('.slideUp').css({top: -$(window).outerHeight()});
} else {
// On Scroll Up
if(sup + $(window).height() < $(document).height()) {
$('.slideUp').css({top: 0});
}
}
lastScrollTop = sup;
}