-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (33 loc) · 1.29 KB
/
index.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
import { bookList } from './modules/BookList.js';
import header from './components/Header.js';
import main from './components/MainSection.js';
import footer from './components/Footer.js';
const renderUserInterface = () => {
document.body.appendChild(header);
document.body.appendChild(main);
document.body.appendChild(footer);
};
window.addEventListener('DOMContentLoaded', () => {
bookList.checkBooks();
renderUserInterface();
const linkItems = document.querySelectorAll('.nav-item');
linkItems.forEach((item) => {
item.addEventListener('click', () => {
const activeLink = document.getElementById(item.id);
const activeSection = document.getElementById(item.id.substring(5));
if (!activeLink.classList.contains('active')) {
activeLink.classList.add('active');
activeSection.classList.remove('d-off');
}
linkItems.forEach((previousItem) => {
const hiddenSection = document.getElementById(previousItem.id.substring(5));
if (previousItem.id !== item.id && previousItem.classList.contains('active')) {
previousItem.classList.remove('active');
}
if (previousItem.id !== item.id && !hiddenSection.classList.contains('d-off')) {
hiddenSection.classList.add('d-off');
}
});
});
});
});