-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
99 lines (74 loc) · 2.78 KB
/
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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
let w = window.innerWidth;
let winScroll = window.scrollY;
const navBar = document.getElementById("navbar");
const navWrapper = document.getElementById("nav");
// FUNCTIONS
function scrollToTargetAdjusted(href){
// console.log(href);
var element = document.getElementById(href);
var headerOffset = 70;
var elementPosition = element.getBoundingClientRect().top;
var offsetPosition = elementPosition + window.scrollY - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
function toggleClass(className, elementID) {
document.getElementById(elementID).classList.toggle(className);
}
function showScrollBar() {
let winScroll = window.scrollY;
const infoToggled = document.getElementById("infolink").classList.contains("toggled");
if (winScroll > 0) {
navBar.style.top = "0";
} else if (winScroll == 0 & infoToggled == false) {
navBar.style.top = "-50px";
}
}
// NAVBAR TOP EDGE HOVER TRIGGER
navWrapper.addEventListener("mouseover", (event) => {
const infoToggled = document.getElementById("infolink").classList.contains("toggled");
let winScroll = window.scrollY;
if (winScroll == 0 & infoToggled == false) {
navBar.style.top = "0";
// console.log("nav shown");
}
navWrapper.addEventListener("mouseleave", (event) => {
const infoToggled = document.getElementById("infolink").classList.contains("toggled");
let winScroll = window.scrollY;
if (winScroll == 0 & infoToggled == false) {
navBar.style.top = "-50px"
// console.log("nav hidden");
}
})
})
// TOGGLES & CLICK FUNCTIONS
const yrSbToggleBtns = document.querySelectorAll('[data-yr-sb-toggle]').forEach(btn => {
btn.addEventListener("click", () => {
toggleClass('hide-yr-sidebar','yr-sidebar');
})
})
const infoDropdownOptionClearToggleWin = document.querySelectorAll('[data-info-dd-option]').forEach(btn => {
btn.addEventListener("click", () => {
toggleClass('info-dropdown-toggled', 'infoWin');
toggleClass('toggled', 'infolink');
})
})
const infoDropdownToggle = document.querySelector('[data-info-dd-toggle]').addEventListener("click", () => {
toggleClass('info-dropdown-toggled', 'infoWin');
toggleClass('toggled', 'infolink');
})
const timelineEvent = document.querySelectorAll('[data-yr-btn]').forEach(anchor => {
let href = anchor.getAttribute('data-yr-btn');
anchor.addEventListener("click", () => {
scrollToTargetAdjusted(href);
})
})
// WINDOW TRIGGER EVENTS
addEventListener("load", () => {
showScrollBar();
});
addEventListener("scroll", () => {
showScrollBar();
});