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' ;
14+ } )
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+ }
35+ } )
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 ( ) ;
0 commit comments