-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
52 lines (45 loc) · 1.92 KB
/
app.js
File metadata and controls
52 lines (45 loc) · 1.92 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
const dropdown = document.querySelector('#dropdown-menu');
const dropdownLinks = document.querySelector('.navbar__menu');
const logo = document.querySelector('#navbar__logo');
const phoneMenu = () => {
dropdown.classList.toggle('is-active');
dropdownLinks.classList.toggle('active');
};
dropdown.addEventListener('click', phoneMenu);
/* Highlights which section of the page is currently being displayed to the user */
const highlightIndicator = () => {
const ele = document.querySelector('.highlight');
const home = document.querySelector('#home-page');
const about = document.querySelector('#about-page');
const contact = document.querySelector('#contact-page');
let scrollPos = window.scrollY;
if (window.innerWidth > 960 && scrollPos < 505){
home.classList.add('highlight');
about.classList.remove('highlight');
return;
} else if (window.innerWidth > 960 && scrollPos < 1400){
about.classList.add('highlight');
home.classList.remove('highlight');
contact.classList.remove('highlight');
return;
} else if (window.innerWidth > 960 && scrollPos < 2345){
contact.classList.add('highlight');
about.classList.remove('highlight');
return;
}
if ((ele && window.innerWidth < 960 && scrollPos < 600) || ele){
ele.classList.remove('highlight')
}
};
window.addEventListener('scroll', highlightIndicator);
window.addEventListener('click', highlightIndicator);
/* Hides the dynamic dropdown menu upon user clicking on one of the options */
const hideDropdown = () => {
const toggler = document.querySelector('.is-active');
if (window.innerWidth <= 960 && toggler){
dropdown.classList.toggle('is-active');
dropdownLinks.classList.toggle('active');
}
}
dropdownLinks.addEventListener('click', hideDropdown);
logo.addEventListener('click', hideDropdown);