-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
28 lines (23 loc) · 835 Bytes
/
app.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
let menuLinks = document.querySelectorAll('.menu__link'),
mainItems = document.querySelectorAll('.main__item'),
mainInner = document.querySelector('.main__inner'),
cloneMainItems = [...mainInner.children];
menuLinks.forEach((ml, v) => {
ml.setAttribute('href', `#t${v+1}`)
ml.setAttribute('data-l', `t${v+1}`)
ml.addEventListener('click', event => {
// event.preventDefault();
mainItems.forEach(item => item.remove(item));
menuLinks.forEach(item => item.classList.remove('menu__active'));
if (!ml.closest('.menu__active')) {
ml.classList.add('menu__active');
cloneMainItems.forEach(item => {
let dh = item.getAttribute('data-h');
if (ml.getAttribute('data-l') == dh) {
mainInner.append(item)
}
})
}
});
});
menuLinks[0].click();