forked from cristinalare/supermodular.xyz
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
96 lines (82 loc) · 2.64 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
// modals
function modalClick(e) {
e.stopPropagation();
return false;
}
const closeModal = (e, modal, overlay) => {
e.stopPropagation();
modal.style.opacity = 0;
overlay.style.opacity = 0;
const closeTimeout = setTimeout(() => {
overlay.style.display = "none";
modal.style.display = "none";
}, 400);
}
const openModal = (modal, overlay) => {
modal.style.display = "block"
overlay.style.display = "block";
const openTimeout = setTimeout(() => {
modal.style.opacity = 1;
overlay.style.opacity = 1;
}, 50);
}
// menu
const menuProjects = document.querySelectorAll('.menu-project');
const menuItems = document.querySelectorAll('.menu-item');
const menuMobileDivider = document.querySelector('.menu-divider-mobile');
const menuIcon = document.querySelector('.menu-icon');
const closeIcon = document.querySelector('.close-icon');
const menuModal = document.querySelector('.menu-modal');
const menuOverlay = document.querySelector('.menu-overlay');
const body = document.body;
menuModal.addEventListener('click', modalClick);
menuIcon.addEventListener("click", () => {
openModal(menuModal, menuOverlay);
closeIcon.style.display = 'block';
menuIcon.style.display = 'none';
body.style.position = 'fixed';
});
closeIcon.addEventListener("click", (e) => {
body.style.position = '';
closeModal(e, menuModal, menuOverlay);
closeIcon.style.display = 'none';
menuIcon.style.display = 'block';
});
menuOverlay.addEventListener("click", (e) => {
body.style.position = '';
closeModal(e, menuModal, menuOverlay);
closeIcon.style.display = 'none';
menuIcon.style.display = 'block';
});
// select menu item
const showProject = (index) => {
menuItems.forEach((item, i) => {
// if (index == i) item.style.color = 'transparent !important';
// else item.style.color = 'white';
if (index == i) item.classList.add('selected');
else item.classList.remove('selected');
});
menuProjects.forEach((proj, i) => {
if (index == i) proj.style.display = 'flex';
else proj.style.display = 'none';
})
if (menuMobileDivider) {
menuModal.scrollTo({
top: menuMobileDivider.offsetTop,
left: 0,
behavior: "smooth",
});
}
}
menuItems.forEach((item, index) => {
item.addEventListener('click', () => {
showProject(index)
})
})
// signup modal
const openModalBtn = document.querySelector("#signup-btn");
const modal = document.querySelector(".signup-modal");
const overlay = document.querySelector(".overlay");
modal.addEventListener('click', modalClick);
openModalBtn.addEventListener("click", () => openModal(modal, overlay));
overlay.addEventListener("click", (e) => closeModal(e, modal, overlay));