-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
33 lines (26 loc) · 957 Bytes
/
script.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
$(document).ready(function () {
var NAV_PADDING = 10;
var navLinks = $('[data-ui="nav-item"]'),
navElement = $('[data-ui="nav"]'),
topOfNav = navElement[0].offsetTop,
navHeight = navElement[0].offsetHeight,
windowElement = $(window);
var resetNavClass = function () {
if (windowElement.scrollTop() >= topOfNav) {
navElement.addClass('nav-stuck');
} else {
navElement.removeClass('nav-stuck');
}
};
windowElement.on('scroll', function () {
resetNavClass();
});
navLinks.on('click', function (event) {
var item = event.target.dataset.navItem,
targetHeaderElement = $('[data-header-item="' + item + '"]')[0],
targetY = targetHeaderElement.offsetTop - targetHeaderElement.offsetHeight - navHeight - NAV_PADDING;
$('html, body').animate({
scrollTop: targetY
}, 1000);
});
});