-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (50 loc) · 1.85 KB
/
script.js
File metadata and controls
63 lines (50 loc) · 1.85 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
// FADE-ON-SCROLL ANIMATION
const faders = document.querySelectorAll('.fadein');
const options = {
threshold: 0,
rootMargin: '0px 0px -150px 0px'
};
const fadeOnScroll = new IntersectionObserver(function(entries, fadeOnScroll) {
entries.forEach(entry => {
if (!entry.isIntersecting) {
return
} else {
entry.target.classList.toggle('noopacity');
fadeOnScroll.unobserve(entry.target);
}
})
}, options);
faders.forEach(fader => {
fadeOnScroll.observe(fader);
})
// DROPDOWN MENU INTERACTION
const togglebutton = document.querySelector('.togglebutton');
const togglebuttonicon = document.querySelector('.togglebutton span');
const dropdown = document.querySelector('.dropdown');
togglebutton.onclick = function () {
dropdown.classList.toggle('open');
const isopen = dropdown.classList.contains('open');
if (isopen)
togglebuttonicon.innerHTML = 'close';
else
togglebuttonicon.innerHTML = 'menu';
}
// ACCORDION CARD INTERACTION (PASSIONS SECTION)
const accordion = document.querySelector('.accordion');
accordion.addEventListener('click', (e) => {
const activePanel = e.target.closest('.accordionpanel');
if (!activePanel) return;
toggleAccordion(activePanel);
})
function toggleAccordion(panelToActivate) {
const buttons = panelToActivate.parentElement.querySelectorAll('.accordiontrigger');
const contents = panelToActivate.parentElement.querySelectorAll('.accordioncontent');
buttons.forEach((button) => {
button.setAttribute('aria-expanded', false);
})
contents.forEach((content) => {
content.setAttribute('aria-hidden', true);
})
panelToActivate.querySelector('.accordiontrigger').setAttribute('aria-expanded', true);
panelToActivate.querySelector('.accordioncontent').setAttribute('aria-hidden', false);
}