-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
564 lines (464 loc) · 21.4 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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/*
Andrew Deal
Professional Website
August 31, 2023
*/
"use strict"
/// Get Elements ///
const r = document.querySelector(':root'); //Get CSS root
// Home page
const greeting = document.getElementById("greeting"); //Each element is found and saved in a js variable
const myName = document.getElementById("name");
const intro = document.getElementById("intro");
const instructions = document.getElementById("instructions")
//About me page
const aboutMeTitle = document.getElementById("aboutMeTitle");
const aboutMeParagraph = document.getElementById("aboutMeParagraph");
const me = document.getElementById("me");
//Projects page
const projectsTitle = document.getElementById("projectsTitle");
const projectsInstructions = document.getElementById("projectsInstructions");
const projectsGallery = document.getElementById("projectsGallery");
//Experience page
const experienceTitle = document.getElementById("experienceTitle");
const experienceDescription = document.getElementById("experienceDescription");
const myResume = document.getElementById("myResume");
//Contact page
const contactTitle = document.getElementById("contactTitle");
const contactBox = document.getElementById("contactBox");
// Get Element Coordinates //
function getCoords() {
//Home
r.style.setProperty('--greetingWidth', `${greeting.getBoundingClientRect().width / 2}px`); //Width is saved in css variable
r.style.setProperty('--greetingHeight', `${greeting.getBoundingClientRect().height / 2}px`); //height is saved in css variable
r.style.setProperty('--myNameWidth', `${myName.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--myNameHeight', `${myName.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--introWidth', `${intro.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--introHeight', `${intro.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--instructionsWidth', `${intro.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--instructionsHeight', `${intro.getBoundingClientRect().height / 2}px`);
//About Me
r.style.setProperty('--aboutMeTitleWidth', `${aboutMeTitle.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--aboutMeTitleHeight', `${aboutMeTitle.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--aboutMeParagraphWidth', `${aboutMeParagraph.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--aboutMeParagraphHeight', `${aboutMeParagraph.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--meWidth', `${me.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--meHeight', `${me.getBoundingClientRect().height / 2}px`);
//Projects
r.style.setProperty('--projectsTitleWidth', `${projectsTitle.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--projectsTitleHeight', `${projectsTitle.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--projectsInstructionsWidth', `${projectsInstructions.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--projectsInstructionsHeight', `${projectsInstructions.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--projectsGalleryWidth', `${projectsGallery.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--projectsGalleryHeight', `${projectsGallery.getBoundingClientRect().height / 2}px`);
//Experience
r.style.setProperty('--experienceTitleWidth', `${experienceTitle.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--experienceTitleHeight', `${experienceTitle.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--experienceDescriptionWidth', `${experienceDescription.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--experienceDescriptionHeight', `${experienceDescription.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--myResumeWidth', `${myResume.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--myResumeHeight', `${myResume.getBoundingClientRect().height / 2}px`);
//Contact
r.style.setProperty('--contactTitleWidth', `${contactTitle.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--contactTitleHeight', `${contactTitle.getBoundingClientRect().height / 2}px`);
r.style.setProperty('--contactBoxWidth', `${contactBox.getBoundingClientRect().width / 2}px`);
r.style.setProperty('--contactBoxHeight', `${contactBox.getBoundingClientRect().height / 2}px`);
}
getCoords();
// Folders //
const allFolders = document.getElementsByClassName("folder");
const homeFolder = allFolders[0];
const aboutMeFolder = allFolders[1];
const projectsFolder = allFolders[2];
const experienceFolder = allFolders[3];
const contactFolder = allFolders[4];
/// Get Folder Positions ///
function findHomeFolder(direction) {
//Get box around folder coords
let rect = homeFolder.getBoundingClientRect();
//Save center x and y to CSS (finding avg x and y)
r.style.setProperty('--homeFolderX', `${(rect.left + rect.right) / 2}px`);
r.style.setProperty('--homeFolderY', `${(rect.top + rect.bottom) / 2}px`);
//Update element coordinates
if (direction === "shrink") {
getCoords();
};
};
function findAboutMeFolder(direction) {
//Get box around folder coords
let rect = aboutMeFolder.getBoundingClientRect();
//Save center x and y to CSS (finding avg x and y)
r.style.setProperty('--aboutMeFolderX', `${(rect.left + rect.right) / 2}px`);
r.style.setProperty('--aboutMeFolderY', `${(rect.top + rect.bottom) / 2}px`);
//Update element coordinates
if (direction === "shrink") {
getCoords();
};
};
function findProjectsFolder(direction) {
//Get box around folder coords
let rect = projectsFolder.getBoundingClientRect();
//Save center x and y to CSS (finding avg x and y)
r.style.setProperty('--projectsFolderX', `${(rect.left + rect.right) / 2}px`);
r.style.setProperty('--projectsFolderY', `${(rect.top + rect.bottom) / 2}px`);
//Update element coordinates
if (direction === "shrink") {
getCoords();
};
};
function findExperienceFolder(direction) {
//Get box around folder coords
let rect = experienceFolder.getBoundingClientRect();
//Save center x and y to CSS (finding avg x and y)
r.style.setProperty('--experienceFolderX', `${(rect.left + rect.right) / 2}px`);
r.style.setProperty('--experienceFolderY', `${(rect.top + rect.bottom) / 2}px`);
//Update element coordinates
if (direction === "shrink") {
getCoords();
};
};
function findContactFolder(direction) {
//Get box around folder coords
let rect = contactFolder.getBoundingClientRect();
//Save center x and y to CSS (finding avg x and y)
r.style.setProperty('--contactFolderX', `${(rect.left + rect.right) / 2}px`);
r.style.setProperty('--contactFolderY', `${(rect.top + rect.bottom) / 2}px`);
//Update element coordinates
if (direction === "shrink") {
getCoords();
};
};
// Variable to keep track of which folder is currently open //
let currentFolder = "home";
/// Functions ///
function shrinkHome() {
//Get home folder coordinates, then apply the animation for each element
findHomeFolder("shrink");
//By setting default scales to 1 here, it ensures that the animation delay does not make them disappear from the page
greeting.style.transform = "scale(1)";
myName.style.transform = "scale(1)";
intro.style.transform = "scale(1)";
instructions.style.transform = "scale(1)";
//Animations
greeting.style.animation = "shrinkAndMoveGreeting 1s 0.6s forwards";
myName.style.animation = "shrinkAndMoveName 1s 0.9s forwards";
intro.style.animation = "shrinkAndMoveIntro 1s 0.3s forwards";
instructions.style.animation = "shrinkAndMoveInstructions 1s forwards";
}
function shrinkAboutMe() {
//Get about me folder coordinates, then apply the animation for each element
findAboutMeFolder("shrink");
//By setting default scales to 1 here, it ensures that the animation delay does not make them disappear from the page
aboutMeTitle.style.transform = "scale(1)";
aboutMeParagraph.style.transform = "scale(1)";
me.style.transform = "scale(1)";
//Animations
aboutMeTitle.style.animation = "shrinkAndMoveAboutMeTitle 1s 0.6s forwards";
aboutMeParagraph.style.animation = "shrinkAndMoveAboutMeParagraph 1s forwards";
me.style.animation = "shrinkAndMoveMe 1s 0.4s forwards";
}
function shrinkProjects() {
//Get projects folder coordinates, then apply the animation for each element
findProjectsFolder("shrink");
//By setting default scales to 1 here, it ensures that the animation delay does not make them disappear from the page
projectsTitle.style.transform = "scale(1)";
projectsInstructions.style.transform = "scale(1)";
projectsGallery.style.transform = "scale(1)";
//Scroll window back to left side so that the project gallery shrinking animation is more smooth
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
});
//Animations
projectsTitle.style.animation = "shrinkAndMoveProjectsTitle 1s 0.6s forwards";
projectsInstructions.style.animation = "shrinkAndMoveProjectsInstructions 1s 0.4s forwards";
projectsGallery.style.animation = "shrinkAndMoveProjectsGallery 1s 0.2s forwards";
//Deactivate Tabindex
let galleryImages = document.getElementsByClassName("galleryImg"); //Get array of all gallery images
for (let i = 0; i < galleryImages.length; i++) {
galleryImages[i].setAttribute("tabindex", "-1"); //Disable tabindex for each, on shrink
};
//Reset cursor
document.documentElement.style.cursor = "auto";
}
function shrinkExperience() {
//Get projects folder coordinates, then apply the animation for each element
findExperienceFolder("shrink");
//By setting default scales to 1 here, it ensures that the animation delay does not make them disappear from the page
experienceTitle.style.transform = "scale(1)";
experienceDescription.style.transform = "scale(1)";
myResume.style.transform = "scale(1)";
//Animations
experienceTitle.style.animation = "shrinkAndMoveExperienceTitle 1s 0.6s forwards";
experienceDescription.style.animation = "shrinkAndMoveExperienceDescription 1s 0.3s forwards";
myResume.style.animation = "shrinkAndMoveMyResume 1s forwards";
//Deactivate Tabindex
myResume.children[2].setAttribute("tabindex", "-1"); //Diable tab index on resume link
}
function shrinkContact() {
//Get projects folder coordinates, then apply the animation for each element
findContactFolder("shrink");
//By setting default scales to 1 here, it ensures that the animation delay does not make them disappear from the page
contactTitle.style.transform = "scale(1)";
contactBox.style.transform = "scale(1)";
//Animations
contactTitle.style.animation = "shrinkAndMoveContactTitle 1s 0.6s forwards";
contactBox.style.animation = "shrinkAndMoveContactBox 1s 0.3s forwards";
//Deactivate Tabindex
//Form elements
document.getElementById("nameInput").setAttribute("tabindex", "-1");
document.getElementById("emailInput").setAttribute("tabindex", "-1");
document.getElementById("messageInput").setAttribute("tabindex", "-1");
document.getElementById("submitContactForm").setAttribute("tabindex", "-1");
//Links to contact info
let contactLinks = document.getElementsByClassName("contactLink"); //Get array of all contact info links
for (let i = 0; i < contactLinks.length; i++) {
contactLinks[i].setAttribute("tabindex", "-1"); //Make each element in the array tab-able
};
}
async function growHome() {
//Shrink whichever folder is open
switch (currentFolder) {
case "home":
return;
case "aboutMe":
shrinkAboutMe();
break;
case "projects":
shrinkProjects();
break;
case "experience":
shrinkExperience();
break;
case "contact":
shrinkContact();
break;
};
//0.6s pause
await new Promise(resolve => setTimeout(resolve, 1200));
//Change the page title
document.title = "Hi, I'm Andrew Deal";
//Tell program that home folder is being opened
currentFolder = "home";
//Get home folder coordinates, then apply the animation for each element
findHomeFolder("grow");
//Set default scales to 0 to avoid visual glitches
greeting.style.transform = "scale(0)";
myName.style.transform = "scale(0)";
intro.style.transform = "scale(0)";
instructions.style.transform = "scale(0)";
//Animations
greeting.style.animation = "growAndMoveGreeting 1s 0.3s forwards";
myName.style.animation = "growAndMoveName 1s forwards";
intro.style.animation = "growAndMoveIntro 1s 0.6s forwards"
instructions.style.animation = "growAndMoveInstructions 1s 0.9s forwards"
}
async function growAboutMe() {
//Shrink whichever folder is open
switch (currentFolder) {
case "home":
shrinkHome();
break;
case "aboutMe":
return;
case "projects":
shrinkProjects();
break;
case "experience":
shrinkExperience();
break;
case "contact":
shrinkContact();
break;
};
//0.6s pause
await new Promise(resolve => setTimeout(resolve, 1200));
//Change the page title
document.title = "About Me";
//Tell program that home folder is being opened
currentFolder = "aboutMe";
//Get home folder coordinates, then apply the animation for each element
findAboutMeFolder("grow");
//Set default scales to 0 to avoid visual glitches
aboutMeTitle.style.transform = "scale(0)";
aboutMeParagraph.style.transform = "scale(0)";
me.style.transform = "scale(0)";
//Animations
aboutMeTitle.style.animation = "growAndMoveAboutMeTitle 1s 0s forwards";
aboutMeParagraph.style.animation = "growAndMoveAboutMeParagraph 1s 0.6s forwards";
me.style.animation = "growAndMoveMe 1s 0.3s forwards";
}
async function growProjects() {
//Shrink whichever folder is open
switch (currentFolder) {
case "home":
shrinkHome();
break;
case "aboutMe":
shrinkAboutMe();
break;
case "projects":
return;
case "experience":
shrinkExperience();
break;
case "contact":
shrinkContact();
break;
};
//0.6s pause
await new Promise(resolve => setTimeout(resolve, 1200));
//Change the page title
document.title = "My Portfolio";
//Tell program that home folder is being opened
currentFolder = "projects";
//Get home folder coordinates, then apply the animation for each element
findProjectsFolder("grow");
//Set default scales to 0 to avoid visual glitches
projectsTitle.style.transform = "scale(0)";
projectsInstructions.style.transform = "scale(0)";
projectsGallery.style.transform = "scale(0)";
//Animations
projectsTitle.style.animation = "growAndMoveProjectsTitle 1s forwards";
projectsInstructions.style.animation = "growAndMoveProjectsInstructions 1s 0.3s forwards";
projectsGallery.style.animation = "growAndMoveProjectsGallery 1s 0.6s forwards";
//Active tabindex for keyboard users
let galleryImages = document.getElementsByClassName("galleryImg"); //Get array of all gallery images
for (let i = 0; i < galleryImages.length; i++) {
galleryImages[i].setAttribute("tabindex", "0"); //Make each element in the array tab-able
};
//Set cursor to grab
document.documentElement.style.cursor = "grab";
}
async function growExperience() {
//Shrink whichever folder is open
switch (currentFolder) {
case "home":
shrinkHome();
break;
case "aboutMe":
shrinkAboutMe();
break;
case "projects":
shrinkProjects();
break;
case "experience":
return;
case "contact":
shrinkContact();
break;
};
//0.6s pause
await new Promise(resolve => setTimeout(resolve, 1200));
//Change the page title
document.title = "Experience and Resume";
//Tell program that home folder is being opened
currentFolder = "experience";
//Get home folder coordinates, then apply the animation for each element
findExperienceFolder("grow");
//Set default scales to 0 to avoid visual glitches
experienceTitle.style.transform = "scale(0)";
experienceDescription.style.transform = "scale(0)";
myResume.style.transform = "scale(0)";
//Animations
experienceTitle.style.animation = "growAndMoveExperienceTitle 1s forwards";
experienceDescription.style.animation = "growAndMoveExperienceDescription 1s 0.6s forwards";
myResume.style.animation = "growAndMoveMyResume 1s 0.3s forwards";
//Active tabindex for keyboard users
myResume.children[2].setAttribute("tabindex", "0"); //Add tab index to resume link
}
async function growContact() {
//Shrink whichever folder is open
switch (currentFolder) {
case "home":
shrinkHome();
break;
case "aboutMe":
shrinkAboutMe();
break;
case "projects":
shrinkProjects();
break;
case "experience":
shrinkExperience();
break;
case "contact":
return;
};
//0.6s pause
await new Promise(resolve => setTimeout(resolve, 1200));
//Change the page title
document.title = "Contact Me!";
//Tell program that home folder is being opened
currentFolder = "contact";
//Get home folder coordinates, then apply the animation for each element
findContactFolder("grow");
//Set default scales to 0 to avoid visual glitches
contactTitle.style.transform = "scale(0)";
contactBox.style.transform = "scale(0)";
//Animations
contactTitle.style.animation = "growAndMoveContactTitle 1s forwards";
contactBox.style.animation = "growAndMoveContactBox 1s 0.4s forwards";
//Active tabindex for keyboard users
//Form elements
document.getElementById("nameInput").setAttribute("tabindex", "0");
document.getElementById("emailInput").setAttribute("tabindex", "0");
document.getElementById("messageInput").setAttribute("tabindex", "0");
document.getElementById("submitContactForm").setAttribute("tabindex", "0");
//Links to contact info
let contactLinks = document.getElementsByClassName("contactLink"); //Get array of all contact info links
for (let i = 0; i < contactLinks.length; i++) {
contactLinks[i].setAttribute("tabindex", "0"); //Make each element in the array tab-able
};
}
/// Add ondblclick events to each folder ///
homeFolder.ondblclick = growHome;
aboutMeFolder.ondblclick = growAboutMe; //Or the updated grow (any folder) function if I figure out how to do that sooner than later
projectsFolder.ondblclick = growProjects; //Or the updated grow (any folder) function if I figure out how to do that sooner than later
experienceFolder.ondblclick = growExperience;
contactFolder.ondblclick = growContact;
///Add on-enter-press event to each folder for accessibilty///
homeFolder.addEventListener('keydown', (event) => {if (event.key === 'Enter') {growHome();}});
aboutMeFolder.addEventListener('keydown', (event) => {if (event.key === 'Enter') {growAboutMe();}});
projectsFolder.addEventListener('keydown', (event) => {if (event.key === 'Enter') {growProjects();}});
experienceFolder.addEventListener('keydown', (event) => {if (event.key === 'Enter') {growExperience();}});
contactFolder.addEventListener('keydown', (event) => {if (event.key === 'Enter') {growContact();}});
/// Give myName an event that keeps its animation ///
//Temporarily disabled because it's buggy
/*
myName.addEventListener('mouseenter', function () {
myName.style.animation = "background-pan 2.5s linear infinite"
});
myName.addEventListener('mouseleave', function () {
myName.style.animation = "none"
});
*/
/// Projects Gallery Scrolling Events ///
let isDragging = false;
let startX = 0;
document.addEventListener('mousedown', (event) => {
if (currentFolder === "projects") {
if (event.button === 0) { // Left mouse button
isDragging = true;
startX = event.clientX;
event.preventDefault();// Prevents text selection during drag
document.documentElement.style.cursor = "grabbing";
}
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
if (currentFolder === 'projects') {
document.documentElement.style.cursor = "grab";
} else {
document.documentElement.style.cursor = "auto";
}
});
document.addEventListener('mousemove', (event) => {
if (isDragging) {
const deltaX = startX - event.clientX;
window.scrollBy(deltaX, 0);
startX = event.clientX;
}
});