Skip to content

Commit fb32d33

Browse files
authored
Update main.js
The remove menu mobile function was added. Added the function scroll section active link. Updated all scroll reveal code.
1 parent a301392 commit fb32d33

1 file changed

Lines changed: 32 additions & 37 deletions

File tree

assets/js/main.js

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,46 @@ const showMenu = (toggleId, navId) =>{
1111
}
1212
showMenu('nav-toggle','nav-menu')
1313

14-
/*===== ACTIVE AND REMOVE MENU =====*/
15-
const navLink = document.querySelectorAll('.nav__link');
14+
/*==================== REMOVE MENU MOBILE ====================*/
15+
const navLink = document.querySelectorAll('.nav__link')
1616

1717
function linkAction(){
18-
/*Active link*/
19-
navLink.forEach(n => n.classList.remove('active'));
20-
this.classList.add('active');
21-
22-
/*Remove menu mobile*/
23-
const navMenu = document.getElementById('nav-menu')
24-
navMenu.classList.remove('show')
18+
const navMenu = document.getElementById('nav-menu')
19+
// When we click on each nav__link, we remove the show-menu class
20+
navMenu.classList.remove('show')
2521
}
26-
navLink.forEach(n => n.addEventListener('click', linkAction));
22+
navLink.forEach(n => n.addEventListener('click', linkAction))
23+
24+
/*==================== SCROLL SECTIONS ACTIVE LINK ====================*/
25+
const sections = document.querySelectorAll('section[id]')
26+
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')
37+
}else{
38+
document.querySelector('.nav__menu a[href*=' + sectionId + ']').classList.remove('active')
39+
}
40+
})
41+
}
42+
window.addEventListener('scroll', scrollActive)
2743

2844
/*===== SCROLL REVEAL ANIMATION =====*/
2945
const sr = ScrollReveal({
3046
origin: 'top',
31-
distance: '80px',
47+
distance: '60px',
3248
duration: 2000,
33-
reset: true
49+
delay: 200,
50+
// reset: true
3451
});
3552

36-
/*SCROLL HOME*/
37-
sr.reveal('.home__title',{});
38-
sr.reveal('.button',{delay: 200});
39-
sr.reveal('.home__img',{delay: 400});
53+
sr.reveal('.home__data, .about__img, .skills__subtitle, .skills__text',{});
54+
sr.reveal('.home__img, .about__subtitle, .about__text, .skills__img',{delay: 400});
4055
sr.reveal('.home__social-icon',{ interval: 200});
41-
42-
/*SCROLL ABOUT*/
43-
sr.reveal('.about__img',{});
44-
sr.reveal('.about__subtitle',{delay: 400});
45-
sr.reveal('.about__text',{delay: 400});
46-
47-
/*SCROLL SKILLS*/
48-
sr.reveal('.skills__subtitle',{});
49-
sr.reveal('.skills__text',{});
50-
sr.reveal('.skills__data',{interval: 200});
51-
sr.reveal('.skills__img',{delay: 600});
52-
53-
/*SCROLL WORK*/
54-
sr.reveal('.work__img',{interval: 200});
55-
56-
/*SCROLL CONTACT*/
57-
sr.reveal('.contact__input',{interval: 200});
58-
59-
60-
61-
56+
sr.reveal('.skills__data, .work__img, .contact__input',{interval: 200});

0 commit comments

Comments
 (0)