-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
165 lines (145 loc) · 4.89 KB
/
main.js
File metadata and controls
165 lines (145 loc) · 4.89 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const hamburger = document.getElementById("hamburger");
hamburger.addEventListener('click', function (event) {
event.preventDefault();
})
function navOpen(isMobile) {
const hamburger = document.getElementById("hamburger");
const hamburger_mobile = document.getElementById("hamburger_mobile");
const p = document.getElementsByClassName("p_top");
const h = document.getElementsByClassName("h1_top");
const nav = document.getElementById("first_parallax").getElementsByClassName("nav")[0]
const isOpen = hamburger.dataset.isOpen;
if (isOpen === 'false') {
if (isMobile) {
nav.style.transform = "translate(-100vw)";
}
else {
nav.style.transform = "translate(-14.6vw)";
}
// Rotate nav image and change to white
hamburger.style.transform = "rotate(90deg)";
hamburger.style.opacity = 0;
hamburger_mobile.style.transform = "rotate(90deg)";
hamburger_mobile.style.opacity = 0;
setTimeout(() => {
hamburger.src="menuwhite.png";
hamburger.style.opacity = 1;
hamburger_mobile.src="menuwhite.png";
hamburger_mobile.style.opacity = 1;
}, 500);
// Set nav as open
hamburger.dataset.isOpen = 'true';
}
else {
if (isMobile) {
nav.style.transform = "translate(100vw)";
}
else {
nav.style.transform = "translate(14.6vw)";
}
// Set nav as closed
hamburger.dataset.isOpen = 'false';
// Rotate nav back to original position and change to black
hamburger.style.transform = "rotate(0deg)";
hamburger.style.opacity = 0;
hamburger_mobile.style.transform = "rotate(0deg)";
hamburger_mobile.style.opacity = 0;
setTimeout(() => {
hamburger.src="menu.png";
hamburger.style.opacity = 1;
hamburger_mobile.src="menu.png";
hamburger_mobile.style.opacity = 1;
}, 200);
}
}
const p = document.getElementsByClassName("p_top");
const h = document.getElementsByClassName("h1_top");
var resizeTimer;
window.onresize = () => {
for (let i = 0; i < p.length; i++) {
p[i].classList.add('no-transition');
}
for (let i = 0; i < h.length; i++) {
h[i].classList.add('no-transition');
}
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
for (let i = 0; i < p.length; i++) {
p[i].classList.remove('no-transition'), 250;
}
for (let i = 0; i < h.length; i++) {
h[i].classList.remove('no-transition'), 250;
}
});
};
// This section counts how many times the arrow blinks
// When the user scrolls down, the arrow blinks the iterCount + 1th time and then disappears
// This isn't just setting variables, it is setting how many times to blink
let iterCount = 0;
let started = false;
const arrow = document.getElementsByClassName("arrow")[0];
arrow.addEventListener("animationstart", () => {
started = true;
})
arrow.addEventListener("animationiteration", () => {
iterCount++;
})
window.history.scrollRestoration = "manual"; // Prevent window from automatically "scrolling" on render
function scrollFunction() {
console.log("Removing arrow");
if (started === false) {
arrow.style.animationIterationCount = 0; // Don't blink if user scrolls before arrow starts blinking
}
else {
arrow.style.animationIterationCount = iterCount + 1;
}
}
window.onscroll = scrollFunction;
function projectReveal(projectIndex) {
const gas = document.getElementById("gas");
const fish = document.getElementById("fish");
const tutor = document.getElementById("typing");
const dashboard = document.getElementById("dashboard");
const license = document.getElementById("license");
if (projectIndex === 0) {
gas.style.opacity = 1;
}
else if (projectIndex === 1) {
fish.style.opacity = 1;
}
else if (projectIndex === 2) {
tutor.style.opacity = 1;
}
else if (projectIndex === 3) {
dashboard.style.opacity = 1;
}
else {
license.style.opacity = 1;
}
}
function projectHide(projectIndex) {
const gas = document.getElementById("gas");
const fish = document.getElementById("fish");
const tutor = document.getElementById("typing");
const dashboard = document.getElementById("dashboard");
const license = document.getElementById("license");
if (projectIndex === 0) {
gas.style.opacity = 0;
}
else if (projectIndex === 1) {
fish.style.opacity = 0;
}
else if (projectIndex === 2) {
tutor.style.opacity = 0;
}
else if (projectIndex === 3) {
dashboard.style.opacity = 0;
}
else {
license.style.opacity = 0;
}
}
const arrow_img = document.getElementById("arrow_img");
if (window.screen.width <= 1366) {
arrow_img.src = "black_arrow.png";
}