-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
76 lines (66 loc) · 2.15 KB
/
app.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
const logo = document.querySelector('.logo');
const hamburger = document.getElementById('hamburger');
const navList = document.getElementById('nav-list');
const menuItems = navList.querySelectorAll('#nav-list li');
menuItems.forEach((item, i) => {
item.style.transitionDelay = `${150 + (i + 1) * 110}ms`;
});
function toggleMobileMenu() {
hamburger.classList.toggle('active');
navList.classList.toggle('show');
document.body.classList.toggle('mobile-menu-open');
}
menuItems.forEach(item => {
item.addEventListener('click', event => {
hamburger.classList.remove('active');
navList.classList.remove('show');
document.body.classList.remove('mobile-menu-open');
});
});
hamburger.addEventListener('click', event => {
toggleMobileMenu();
});
const motionMediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
if (!motionMediaQuery.matches) {
VanillaTilt.init(document.querySelectorAll('.project'), {
max: 3,
speed: 400,
reverse: true,
scale: 1.05,
});
}
const viewportWidthMediaQuery = window.matchMedia('(max-width: 800px)');
function handleWidthChange(evt) {
if (!evt.matches) {
navList.classList.remove('show');
hamburger.classList.remove('active');
document.body.classList.remove('mobile-menu-open');
}
}
viewportWidthMediaQuery.addEventListener('change', handleWidthChange);
function onEnterViewPort(entries, observer) {
entries.forEach(function (entry) {
// Fade in when we enter the viewport
if (entry.intersectionRatio !== 0) {
entry.target.classList.add('visible');
}
});
}
const fadeInObserver = new IntersectionObserver(onEnterViewPort, {
threshold: [1],
});
const fadeIns = document.querySelectorAll('.fade-in');
fadeIns.forEach(elm => fadeInObserver.observe(elm));
function onMainEnter(entries, observer) {
const entry = entries[0];
if (entry.intersectionRatio >= 0.05 || entry.boundingClientRect.y < 0) {
document.body.classList.add('scrolled');
} else {
document.body.classList.remove('scrolled');
}
}
const mainObserver = new IntersectionObserver(onMainEnter, {
threshold: [0.05],
});
const mainElm = document.querySelector('main');
mainObserver.observe(mainElm);