-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
57 lines (48 loc) · 1.47 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
const header = document.getElementById('header');
const nav = document.getElementById('nav');
const scrollElements = document.querySelectorAll('.scroll');
const skillElements = document.querySelectorAll('.skillbar');
//navigation bar functions:
function menuScroll(){
if(window.scrollY > header.offsetHeight+ 400){
header.style.height = '50px';
header.style.opacity ='1';
nav.style.height = '50px';
nav.style.opacity = '1';
} else {
header.style.height = '0';
header.style.opacity ='0';
nav.style.height = '0';
nav.style.opacity = '0';
}
}
window.addEventListener('scroll', menuScroll);
//scroll function:
scrollElements.forEach((el) => {
el.style.opacity = 0;
})
const elementInView = (el, percentageScroll = 100) => {
const elementTop = el.getBoundingClientRect().top;
return (elementTop <= (window.innerHeight || document.documentElement.clientHeight) * (percentageScroll/100));
}
const displayScrollElement = (element) => {
element.classList.add('active');
}
const handleScrollAnimation = () => {
scrollElements.forEach((el) => {
if(elementInView(el, 100)){
displayScrollElement(el);
}
})
}
const growScrollAnimation = () =>{
skillElements.forEach((skill) => {
if(elementInView(skill, 100)){
skill.classList.add('grow');
}
})
}
window.addEventListener('scroll', () => {
handleScrollAnimation();
growScrollAnimation();
})