-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (40 loc) · 1.27 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
const menu = document.querySelector("#menu-btn");
const header = document.querySelector(".header");
const message = document.querySelector('.message');
window.onload = () => {
window.location.href = "#home";
}
menu.onclick = () => {
menu.classList.toggle('fa-times');
header.classList.toggle('active');
document.body.classList.toggle('active');
}
document.addEventListener('keydown', function(event) {
if (event.key === 'q') {
menu.click();
}
});
if (message) {
setTimeout(() => {
message.remove();
}, 5000);
}
window.onscroll = () => {
if (window.innerWidth < 991) {
menu.classList.remove('fa-times');
header.classList.remove('active');
document.body.classList.remove('active');
}
document.querySelectorAll('section').forEach(sec => {
let top = window.scrollY;
let offset = sec.offsetTop - 150;
let height = sec.offsetHeight;
let id = sec.getAttribute('id');
if (top >= offset && top < offset + height) {
document.querySelectorAll('.header .navbar a').forEach(links => {
links.classList.remove('active');
document.querySelector('.header .navbar a[href*='+ id +']').classList.add('active');
});
}
});
}