-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (58 loc) · 1.77 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$(function handleReady() {
(function handleSmoothScrollLinks() {
var $link = $('.smooth-scroll-link');
var $htmlBody = $('html, body');
function handleLinkClick(e) {
e.preventDefault();
var href = this.getAttribute('href');
scrollTo(href, 56 + 16);
}
function scrollTo(ref, offsetTop) {
var top = 0;
offsetTop = offsetTop || 0;
if (ref !== '#') {
top = $(ref).offset().top;
}
$htmlBody.animate({
scrollTop: Math.max(top - offsetTop, 0)
}, 500);
}
$link.click(handleLinkClick);
})();
(function handleStickyNav() {
var $nav = $('.navbar');
var isNavSticky = false;
var STICKY_NAV_TRIGGER_POINT = 56 * 3;
var NAV_TRANSITION_DURATION = 200;
function transitionInStickyNav() {
$nav.addClass('fixed-top bg-white bs-2-15');
setTimeout(function() {
$nav.addClass('is-transitioning fixed-top-sticky');
setTimeout(function() {
$nav.removeClass('is-transitioning');
}, NAV_TRANSITION_DURATION);
}, 0);
isNavSticky = true;
}
function transitionOutStickyNav() {
$nav.removeClass('fixed-top fixed-top-sticky');
$nav.addClass('is-transitioning');
setTimeout(function() {
$nav.removeClass('bg-white bs-2-15');
setTimeout(function() {
$nav.removeClass('is-transitioning');
}, NAV_TRANSITION_DURATION);
}, 0);
isNavSticky = false;
}
function handleScroll(e) {
if (!isNavSticky && window.scrollY >= STICKY_NAV_TRIGGER_POINT) {
transitionInStickyNav();
} else if (isNavSticky && window.scrollY < 1) {
transitionOutStickyNav();
}
}
window.addEventListener('scroll', handleScroll);
handleScroll();
})();
});