Skip to content

Commit 63d562f

Browse files
authored
Update app.js
I know it would not be going along with the course you are providing, but it is a lot simpler that way.
1 parent 1f1c020 commit 63d562f

1 file changed

Lines changed: 11 additions & 43 deletions

File tree

app.js

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,13 @@
1-
const sections = document.querySelectorAll('.section');
2-
const sectBtns = document.querySelectorAll('.controlls');
3-
const sectBtn = document.querySelectorAll('.control');
4-
const allSections = document.querySelector('.main-content');
5-
6-
7-
function PageTransitions(){
8-
//Button click active class
9-
for(let i = 0; i < sectBtn.length; i++){
10-
sectBtn[i].addEventListener('click', function(){
11-
let currentBtn = document.querySelectorAll('.active-btn');
12-
currentBtn[0].className = currentBtn[0].className.replace('active-btn', '');
13-
this.className += ' active-btn';
1+
(function () {
2+
[...document.querySelectorAll(".control")].forEach(button => {
3+
button.addEventListener("click", function() {
4+
document.querySelector(".active-button").classList.remove("active-button");
5+
this.classList.add("active-button");
6+
document.querySelector(".active").classList.remove("active");
7+
document.getElementById(button.dataset.id).classList.add("active");
148
})
15-
}
16-
17-
//Sctions Active
18-
allSections.addEventListener('click', (e) =>{
19-
const id = e.target.dataset.id;
20-
if(id){
21-
//resmove selected from the other btns
22-
sectBtns.forEach((btn) =>{
23-
btn.classList.remove('active')
24-
})
25-
e.target.classList.add('active')
26-
27-
//hide other sections
28-
sections.forEach((section)=>{
29-
section.classList.remove('active')
30-
})
31-
32-
const element = document.getElementById(id);
33-
element.classList.add('active');
34-
}
9+
});
10+
document.querySelector(".theme-btn").addEventListener("click", () => {
11+
document.body.classList.toggle("light-theme");
3512
})
36-
37-
//Toggle theme
38-
const themeBtn = document.querySelector('.theme-btn');
39-
themeBtn.addEventListener('click',() =>{
40-
let element = document.body;
41-
element.classList.toggle('light-mode')
42-
})
43-
}
44-
45-
PageTransitions();
13+
})();

0 commit comments

Comments
 (0)