-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
104 lines (91 loc) · 3.11 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
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
'use strict';
// home title animation
document.addEventListener('DOMContentLoaded',()=>{
new TypeIt('#title')
.pause(500)
.delete(4, { delay: 1000 })
.type(' Dream Coder ')
.go();
});
// Make navbar transparent when it is on the top
const navbar = document.querySelector('#navbar');
const navbarHeight = navbar.getBoundingClientRect().height;
document.addEventListener('scroll', () => {
if (window.scrollY > navbarHeight) {
navbar.classList.add('navbar--dark');
} else {
navbar.classList.remove('navbar--dark');
}
});
// Handle scrolling when tapping on the navbar menu
const navbarMenu = document.querySelector('.navbar__menu');
navbarMenu.addEventListener('click', (event) => {
const target = event.target;
const link = target.dataset.link;
if (link == null) {
return;
}
navbarMenu.classList.remove('open');
scrollIntoView(link);
});
// Navbar toggle button for small screen
const navbarToggleBtn = document.querySelector('.navbar__toggle-btn');
navbarToggleBtn.addEventListener('click', () => {
navbarMenu.classList.toggle('open');
});
// Handle click on "contact me" button on home
const homeContactBtn = document.querySelector('.home__contact');
homeContactBtn.addEventListener('click', () => {
scrollIntoView('#contact');
});
// Make home slowly fade to transparent as the window scrolls down
// const home = document.querySelector('.home__container');
// const homeHeight = home.getBoundingClientRect().height;
// document.addEventListener('scroll', () => {
// home.style.opacity = 1 - window.scrollY / homeHeight;
// });
// Show "arrow up" button when scrolling down
// const arrowUp = document.querySelector('.arrow-up');
// document.addEventListener('scroll', () => {
// if (window.scrollY > homeHeight / 2) {
// arrowUp.classList.add('visible');
// } else {
// arrowUp.classList.remove('visible');
// }
// });
// Handle click on the "arrow up" button
// arrowUp.addEventListener('click', () => {
// scrollIntoView('#home');
// });
// Projects
const workBtnContainer = document.querySelector('.work__categories');
const projectContainer = document.querySelector('.work__projects');
const projects = document.querySelectorAll('.project');
workBtnContainer.addEventListener('click', (e) => {
const filter = e.target.dataset.filter || e.target.parentNode.dataset.filter;
if (filter == null) {
return;
}
// Remove selection from the previous item and select the new one
const active = document.querySelector('.category__btn.selected');
if (active != null) {
active.classList.remove('selected');
}
e.target.classList.add('selected');
projectContainer.classList.add('anim-out');
setTimeout(() => {
projects.forEach((project) => {
console.log(project.dataset.type);
if (filter === '*' || filter === project.dataset.type) {
project.classList.remove('invisible');
} else {
project.classList.add('invisible');
}
});
projectContainer.classList.remove('anim-out');
}, 300);
});
function scrollIntoView(selector) {
const scrollTo = document.querySelector(selector);
scrollTo.scrollIntoView({ behavior: 'smooth' });
}