forked from aslams2020/Stark-Tech-Portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
59 lines (46 loc) · 1.76 KB
/
script.js
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
50
51
52
53
54
55
56
57
58
burger = document.querySelector('.burger');
navbar = document.querySelector('.navbar');
navList = document.querySelector('.nav-list');
rightNav = document.querySelector('.rightNav');
burger.addEventListener('click', ()=>{
rightNav.classList.toggle('visibility');
navList.classList.toggle('visibility');
navbar.classList.toggle('h-nav');
})
function handleLink(){
if (window.innerWidth < 1020) {
rightNav.classList.toggle('visibility');
navList.classList.toggle('visibility');
navbar.classList.toggle('h-nav');
}
}
const currentYear = new Date().getFullYear();
document.getElementById('year').textContent = currentYear;
//logo action
document.getElementById('ironmask').addEventListener('click', () => {
document.getElementById('home').scrollIntoView({ behavior: 'smooth'});
});
//highlight functionality
window.addEventListener('scroll', () => {
const sections=document.querySelectorAll('section');
const navLinks=document.querySelectorAll('nav a');
let current='';
sections.forEach(section => {
const sectionTop = section.offsetTop; //get the distance from the top
if(pageYOffset===0){
current='home';
}
else if(pageYOffset >= sectionTop - section.clientHeight/3.8){ //activate the hightlight when u have scrolled 1/3rd of that section
current = section.getAttribute('id');
}
});
//to know if i have reached the bottom of the page
const docHeight= document.documentElement.scrollHeight;
const windowHeight=window.innerHeight;
if(window.scrollY+windowHeight>=docHeight-200){
current='contact';
}
navLinks.forEach(link => {
link.classList.toggle('active', link.getAttribute('href').includes(current));
});
});