-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
295 lines (260 loc) · 10.9 KB
/
script.js
File metadata and controls
295 lines (260 loc) · 10.9 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
const navbar = document.getElementById('navbar');
// NAVBAR EVENT LISTENER
let lastScrollValue = 0;
document.addEventListener('scroll', (e) => {
var currentScrollValue = window.scrollY;
if(lastScrollValue < currentScrollValue) {
navbar.style.marginTop = '-14rem';
} else {
navbar.style.marginTop = 0;
}
lastScrollValue = currentScrollValue;
});
// ABOUT SECTION WORD WALL
const wordWall = document.getElementById('word-wall');
const worldWallHeight = 100;
// default 10
const numberOfRows = 10;
const wordFontSize = worldWallHeight / numberOfRows;
// default 5
const minAnimationTime = 5;
// default 10
const maxAnimationTime = 10;
// default 0.1
const minOpacity = 0.1;
// default 0.5
const maxOpacity = 0.5;
// default 50
const numberOfWords = 50;
const wordsArr = ['<body>', '</body>', '<nav>', '</nav>', '<section>', '</section>', '<div>', '</div>', '<h1>Hello World</h1>', '<p>Welcome to my page</p>', '<ul>', '</ul>', '<br>', '<li>', '</li>', '<a>', '</a>', '<hr>', '<footer>', '</footer>', '<button>Contact me</button>', '<head>', '</head>', '<script>', '</script>', '<img>'];
let wordWallRows = [];
let animationTime = [];
for (let r = 0; r < numberOfRows; r++) {
wordWallRows.push([]);
animationTime.push([]);
}
function createWordElement() {
let newWordElement = document.createElement('p');
newWordElement.innerText = wordsArr[Math.floor(Math.random() * wordsArr.length)];
let newWordElementRow = Math.floor(Math.random() * numberOfRows);
let fontAndLineHeight = `${wordFontSize / 2}vw`;
newWordElement.style.fontSize = fontAndLineHeight;
newWordElement.style.lineHeight = fontAndLineHeight;
newWordElement.style.top = `${newWordElementRow * wordFontSize}%`;
newWordElement.style.left = '-100%';
newWordElement.style.opacity = minOpacity + Math.random() * (maxOpacity - minOpacity);
let newAnimationTime = minAnimationTime * 1000 + (Math.random() * (maxAnimationTime - minAnimationTime) * 1000);
animationTime[newWordElementRow].push(newAnimationTime);
wordWallRows[newWordElementRow].push(newWordElement);
}
for (let z=0; z < numberOfWords; z++) {
createWordElement();
}
let sortedWordWallRows = [];
let sortedAnimationTime = [];
for (let z=0; z < wordWallRows.length; z++) {
let newRow = wordWallRows[z].sort((a, b) => {return a.style.opacity - b.style.opacity});
sortedWordWallRows.push(newRow);
let newAnimationRow = animationTime[z].sort((a, b) => {return b - a});
sortedAnimationTime.push(newAnimationRow);
}
for (let z=0; z < sortedWordWallRows.length; z++) {
for (let y=0; y < sortedWordWallRows[z].length; y++) {
sortedWordWallRows[z][y].style.animation = `word-wall ${sortedAnimationTime[z][y]}ms ${Math.random() * maxAnimationTime * 1000}ms linear infinite`;
wordWall.append(sortedWordWallRows[z][y]);
}
}
// PROJECTS
const projects = document.getElementById('projects-display');
const projectsList = [];
const projectsArray = [
{
projectName: 'Image Gallery',
projectUrl: 'https://david0z.github.io/image-gallery/',
projectImage: '/resources/image_gallery.png',
projectTools: ['React.js', 'styled-components', 'react-icons', 'uuid', 'react-masonry-css', 'react-intersection-observer', 'framer-motion']
},
{
projectName: 'Audio Playlist',
projectUrl: 'https://david0z.github.io/sound-playlist/',
projectImage: '/resources/playlist_app.png',
projectTools: ['React.js, SCSS', 'react-beautiful-dnd', 'react-icons', 'uuid']
},
{
projectName: 'Choropleth Map',
projectUrl: 'https://david0z.github.io/choropleth-map/',
projectImage: '/resources/usmap.png',
projectTools: ['HTML, CSS, Javascript', 'React.js', 'D3.js']
},
{
projectName: 'Calculator',
projectUrl: 'https://david0z.github.io/calculator/',
projectImage: '/resources/calculator.png',
projectTools: ['HTML, CSS, Javascript', 'Math.js']
},
{
projectName: 'Drum Machine',
projectUrl: 'https://david0z.github.io/sound-machine/',
projectImage: '/resources/drum.png',
projectTools: ['HTML, CSS, Javascript']
},
{
projectName: 'Product Landing Page',
projectUrl: 'https://david0z.github.io/product-landing-page/',
projectImage: '/resources/cola.png',
projectTools: ['HTML, CSS']
}
];
const listLength = projectsArray.length;
function returnTools(index) {
let htmlstring='';
for (let j=0; j < projectsArray[index].projectTools.length; j++) {
htmlstring+= `• ${projectsArray[index].projectTools[j]}<br>`;
}
return htmlstring;
}
const firstFrame = document.createElement('div');
firstFrame.innerText = 'First frame';
firstFrame.classList.add('frame', 'invisible');
projectsList.push(firstFrame);
for (let i = 0; i < listLength; i++) {
const frame = document.createElement('div');
const card = document.createElement('div');
const frontSide = document.createElement('div');
const backSide = document.createElement('div');
frontSide.style.backgroundImage = `url(${projectsArray[i].projectImage})`;
// Fill in
backSide.innerHTML =
`<div class="frame-back-left"><h5>Tools used:</h5><p>${returnTools(i)}</p></div>
<div class="frame-back-right"><a href="${projectsArray[i].projectUrl}" target="_blank">Click here to preview</a></div>`;
// Fill in
frame.append(card);
card.append(frontSide);
card.append(backSide);
frame.classList.add('frame');
card.classList.add('frame-card');
frontSide.classList.add('frame-front');
backSide.classList.add('frame-back');
if(i > 1) {
frame.classList.add('transparent');
}
if(i == 0) {
frame.classList.add('displaying');
}
if(i >= 1) {
frame.classList.add('frame-right');
}
projectsList.push(frame);
}
const finalFrame = document.createElement('div');
finalFrame.innerText = 'Final frame';
finalFrame.classList.add('frame', 'invisible');
projectsList.push(finalFrame);
for (let i = 0; i < projectsList.length; i++) {
projects.append(projectsList[i]);
}
const projectsTitle = document.getElementById('projects-title');
projectsTitle.innerText = projectsArray[0].projectName;
const projectsTitleTransitionTime = parseFloat(getComputedStyle(document.querySelector(':root')).getPropertyValue('--displaying-transition-time').slice(0, this.length - 1)) * 1000;
let currentyDisplayed = 1;
const frameMargin = parseFloat(getComputedStyle(document.querySelector('.frame')).getPropertyValue('--margin').slice(0, this.length - 3));
const frameWidth = parseFloat(getComputedStyle(document.querySelector('.frame')).getPropertyValue('--width').slice(0, this.length - 3));
let currentMargin = frameMargin + (frameWidth + 2 * frameMargin) * (listLength - 1);
document.querySelector('.invisible:first-child').style.marginLeft = currentMargin + 'rem';
const setLeftMargin = function(newMargin) {
document.querySelector('.invisible:first-child').style.marginLeft = newMargin + 'rem';
}
document.querySelectorAll(".projects-menu-button").forEach(element => {
element.addEventListener('click', (e) => {
if(e.target.id === 'projects-menu-left' && currentyDisplayed > 1) {
currentMargin+= (frameWidth + 2 * frameMargin)*2;
setLeftMargin(currentMargin);
projectsList[currentyDisplayed].classList.toggle('displaying');
projectsList[currentyDisplayed].classList.toggle('frame-right');
projectsList[currentyDisplayed - 1].classList.toggle('frame-left');
projectsList[currentyDisplayed - 1].classList.toggle('displaying');
projectsList[currentyDisplayed - 2].classList.toggle('transparent');
projectsList[currentyDisplayed + 1].classList.toggle('transparent');
projectsTitle.style.opacity = 0;
document.querySelectorAll('.projects-menu-button').forEach(button => {
button.disabled = true;
});
setTimeout(() => {
projectsTitle.style.opacity = 1;
projectsTitle.innerText = projectsArray[currentyDisplayed - 1].projectName;
document.querySelectorAll('.projects-menu-button').forEach(button => {
button.disabled = false;
});
}, projectsTitleTransitionTime / 2);
currentyDisplayed--;
} else if (e.target.id === 'projects-menu-right' && currentyDisplayed < projectsList.length - 2) {
currentMargin-= (frameWidth + 2 * frameMargin)*2;
setLeftMargin(currentMargin);
projectsList[currentyDisplayed].classList.toggle('displaying');
projectsList[currentyDisplayed].classList.toggle('frame-left');
projectsList[currentyDisplayed + 1].classList.toggle('frame-right');
projectsList[currentyDisplayed + 1].classList.toggle('displaying');
currentyDisplayed++;
projectsTitle.style.opacity = 0;
document.querySelectorAll('.projects-menu-button').forEach(button => {
button.disabled = true;
});
setTimeout(() => {
projectsTitle.style.opacity = 1;
projectsTitle.innerText = projectsArray[currentyDisplayed - 1].projectName;
document.querySelectorAll('.projects-menu-button').forEach(button => {
button.disabled = false;
});
}, projectsTitleTransitionTime / 2);
if(currentyDisplayed > 1) {
projectsList[currentyDisplayed - 2].classList.toggle('transparent');
projectsList[currentyDisplayed + 1].classList.toggle('transparent');
}
} else {
return;
}
})
})
// INTERSECTION OBSERVERS
// section header observer
const sectionHeaderParent = document.querySelectorAll(".section-title");
const sectionHeaderObserver = new IntersectionObserver (
entries => {
entries.forEach(entry => {
entry.target.querySelector('.section-header').classList.toggle('show', entry.isIntersecting);
});
},
{
threshold: 1
}
);
sectionHeaderParent.forEach(header => {
sectionHeaderObserver.observe(header);
});
// contact menu observer
const contactMenu = document.querySelector("#contact-menu");
const contactButtonObserver = new IntersectionObserver (
entries => {
entries.forEach(entry => {
entry.target.querySelectorAll('a').forEach(button => {
button.classList.toggle('show', entry.isIntersecting);
});
});
},
{
threshold: 0.9
}
);
contactButtonObserver.observe(contactMenu);
const projectsDiv = document.getElementById('projects');
const projectsDivObserver = new IntersectionObserver (
entries => {
entries.forEach(entry => {
entry.target.classList.toggle("show", entry.isIntersecting);
});
},
{
threshold: 0.5
}
);
projectsDivObserver.observe(projectsDiv);