-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (42 loc) · 1.71 KB
/
script.js
File metadata and controls
51 lines (42 loc) · 1.71 KB
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
const sections = document.querySelectorAll('.section');
const sectBtns = document.querySelectorAll('.control'); // Updated to directly target buttons
const allSections = document.querySelector('.main-content');
function PageTransitions() {
// Button click active class
sectBtns.forEach((btn) => {
btn.addEventListener('click', function () {
// Remove active class from previous button
let currentBtn = document.querySelector('.active-btn');
if (currentBtn) {
currentBtn.classList.remove('active-btn');
}
this.classList.add('active-btn');
// Remove active class from previous section and show the corresponding one
const sectionId = this.dataset.id; // Assuming each button has a `data-id` attribute corresponding to the section class
sections.forEach((section) => {
section.classList.remove('active');
});
document.querySelector(`.${sectionId}`).classList.add('active');
});
});
// Section Active
allSections.addEventListener('click', (e) => {
const id = e.target.dataset.id;
if (id) {
// Remove active class from other buttons
sectBtns.forEach((btn) => {
btn.classList.remove('active');
});
e.target.classList.add('active');
// Hide other sections
sections.forEach((section) => {
section.classList.remove('active');
});
// Show the targeted section
const element = document.getElementById(id);
element.classList.add('active');
}
});
}
// Call the function
PageTransitions();