-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
54 lines (44 loc) · 1.56 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
//MENU SHOW
const showMenu = (toggleId, navId) => {
const toggle = document.getElementById(toggleId);
const nav = document.getElementById(navId);
if (toggle && nav) {
toggle.addEventListener("click", () => {
nav.classList.toggle("show");
});
}
};
showMenu("nav-toggle", "nav-menu");
//REMOVE MENU
const navLink = document.querySelectorAll(".nav__link");
const navMenu = document.getElementById("nav-menu");
//difference funct et const ()
function linkAction() {
navMenu.classList.remove('show');
}
//difference between '' and ""
navLink.forEach(n => n.addEventListener("click", linkAction));
//SCROLL SECTIONS ACTIVE LINK
const sections = document.querySelectorAll("section[id]");
window.addEventListener("scroll", scrollActive);
function scrollActive() {
const scrollY = window.pageYOffset;
sections.forEach(current => {
const sectionHeight = current.offsetHeight;
const sectionTop = current.offsetTop - 50;
const sectionId = current.getAttribute('id');
//search course about selector [xxx] and difference between '' and ""
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
document.querySelector('.nav__menu a[href*=' + sectionId + ']').classList.add('active');
} else {
document.querySelector('.nav__menu a[href*=' + sectionId + ']').classList.remove('active');
}
});
}
//CHANGE COLOR HEADER
//simplifly this part
window.onscroll = () => {
const nav = document.getElementById('header');
if (this.scrollY >= 200) nav.classList.add('scroll-header');
else nav.classList.remove('scroll-header');
};