-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
79 lines (60 loc) · 1.91 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
window.addEventListener("scroll", onScroll);
onScroll();
function onScroll(){
changeNavbarColor();
backToTop();
activedMenuAtcurrentSection(home);
activedMenuAtcurrentSection(services);
activedMenuAtcurrentSection(about);
activedMenuAtcurrentSection(contact);
}
function activedMenuAtcurrentSection(section) {
const targetLine = scrollY + innerHeight / 2;
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionEndsAt = sectionTop + sectionHeight;
const sectionTopReachedOrPassedTargetLine = targetLine >= sectionTop;
const sectionEndPassedTargetLine = sectionEndsAt <= targetLine;
const sectionBundaries = sectionTopReachedOrPassedTargetLine && !sectionEndPassedTargetLine;
const sectionId = section.getAttribute('id');
const menuElement = document.querySelector(`.menu a[href*='${sectionId}']`);
menuElement.classList.remove('active');
if(sectionBundaries) {
menuElement.classList.add('active');
}
}
function backToTop(){
let btnBackToTop = document.getElementById('btnBackToTop');
if(scrollY >= 500){
btnBackToTop.classList.add('show');
} else {
btnBackToTop.classList.remove('show');
}
}
function changeNavbarColor(){
let navigationId = document.getElementById('navigation');
if(scrollY > 0){
navigationId.classList.add("scroll");
} else{
navigationId.classList.remove("scroll");
}
}
function openAndCloseMenu(isOpen){
switch(isOpen){
case true:
document.body.classList.add("menu-expanded");
break;
case false:
document.body.classList.remove("menu-expanded");
break;
}
}
ScrollReveal({
origin: 'top',
distance: '3rem',
duration: 700
}).reveal(`
#home, #home img, #home .statistics,
#services header, #services .card,
#about, #about .content, #about img
`);