@@ -24,19 +24,20 @@ navLink.forEach(n => n.addEventListener('click', linkAction))
2424/*==================== SCROLL SECTIONS ACTIVE LINK ====================*/
2525const sections = document . querySelectorAll ( 'section[id]' )
2626
27- function scrollActive ( ) {
28- const scrollY = window . pageYOffset
29-
30- sections . forEach ( current => {
31- const sectionHeight = current . offsetHeight
32- const sectionTop = current . offsetTop - 50 ;
33- sectionId = current . getAttribute ( 'id' )
34-
35- if ( scrollY > sectionTop && scrollY <= sectionTop + sectionHeight ) {
36- document . querySelector ( '.nav__menu a[href*=' + sectionId + ']' ) . classList . add ( 'active' )
27+ const scrollActive = ( ) => {
28+ const scrollDown = window . scrollY
29+
30+ sections . forEach ( current => {
31+ const sectionHeight = current . offsetHeight ,
32+ sectionTop = current . offsetTop - 58 ,
33+ sectionId = current . getAttribute ( 'id' ) ,
34+ sectionsClass = document . querySelector ( '.nav__menu a[href*=' + sectionId + ']' )
35+
36+ if ( scrollDown > sectionTop && scrollDown <= sectionTop + sectionHeight ) {
37+ sectionsClass . classList . add ( 'active-link' )
3738 } else {
38- document . querySelector ( '.nav__menu a[href*=' + sectionId + ']' ) . classList . remove ( 'active' )
39- }
39+ sectionsClass . classList . remove ( 'active-link ' )
40+ }
4041 } )
4142}
4243window . addEventListener ( 'scroll' , scrollActive )
0 commit comments