-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveBox.js
39 lines (29 loc) · 1.19 KB
/
ActiveBox.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
document.addEventListener('DOMContentLoaded', () => {
//fixed header
const header = document.querySelector('#header');
const intro = document.querySelector('#intro');
scrollHeader();
document.addEventListener('scroll', scrollHeader);
function scrollHeader() {
if (window.pageYOffset >= intro.clientHeight) {
header.classList.add('fixed');
} else header.classList.remove('fixed');
}
//smooth scroll
const nav = document.querySelector('#nav');
nav.addEventListener('click', (event)=> {
event.preventDefault();
if(event.target.hasAttribute('data-scroll')) {
let dataScroll = event.target.getAttribute('data-scroll');
let idElement = document.querySelector(dataScroll);
scrollBy(0, idElement.getBoundingClientRect().top - 60);
nav.classList.contains('show') ? nav.classList.remove('show') : false;
}
});
//nav Togle
const burger = document.querySelector('#navTogle');
burger.addEventListener('click', (event)=> {
event.preventDefault();
nav.classList.contains('show') ? nav.classList.remove('show') : nav.classList.add('show');
})
})