-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
103 lines (91 loc) · 3.05 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// show menu
const showMenu = (toggleId, navId) => {
const toggle = document.getElementById(toggleId),
nav = document.getElementById(navId);
if (toggle && nav) {
toggle.addEventListener("click", () => {
nav.classList.toggle("show-menu");
});
}
};
showMenu("nav-toggle", "nav-menu");
// remove menu mobile
const navLink = document.querySelectorAll(".nav__link");
function linkAction() {
const navMenu = document.getElementById("nav-menu");
navMenu.classList.remove("show-menu");
}
navLink.forEach((n) => n.addEventListener("click", linkAction));
// // scroll sections active link
// const sections = document.querySelectorAll("section[id]");
// function scrollActive() {
// const scrollY = window.pageYOffset;
// sections.forEach((current) => {
// const sectionHeight = current.offsetHeight;
// const sectionTop = current.offsetTop - 50;
// sectionId = current.getAttribute("id");
// if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
// document
// .querySelector(".nav__menu a[href*=" + sectionId + "]")
// .classList.add("active-link");
// } else {
// document
// .querySelector(".nav__menu a[href*=" + sectionId + "]")
// .classList.remove("active-link");
// }
// });
// }
// window.addEventListener("scroll", scrollActive);
//change background header
function scrollHeader() {
const nav = document.getElementById("header");
if (this.scrollY >= 200) {
nav.classList.add("scroll-header");
} else {
nav.classList.remove("scroll-header");
}
}
window.addEventListener("scroll", scrollHeader);
//show scroll top
function scrollTop() {
const scrollTop = document.getElementById("scroll-top");
if (this.scrollY >= 560) {
scrollTop.classList.add("scroll-top");
} else {
scrollTop.classList.remove("scroll-top");
}
}
window.addEventListener("scroll", scrollTop);
//dark theme
const themeButton = document.getElementById('theme-button');
const darkTheme = 'dark-theme';
const iconTheme = 'bx-sun';
themeButton.addEventListener('click', () => {
document.body.classList.toggle(darkTheme);
themeButton.classList.toggle(iconTheme);
localStorage.setItem('selected-theme', getCurrentTheme());
localStorage.setItem('selected-icon', getCurrentIcon());
});
const selectedTheme = localStorage.getItem('selected-theme');
const selectedIcon = localStorage.getItem('selected-icon');
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light';
const getCurrentIcon = () => themeButton.classList.contains(iconTheme) ? 'bx-moon' : 'bx-sun';
if(selectedTheme){
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme);
themeButton.classList[selectedIcon === 'bx-moon' ? 'add' : 'remove'](iconTheme);
}
//scroll reveal effect
const sr = ScrollReveal({
origin: 'top',
distance: '30px',
duration: 2000,
reset: true
})
sr.reveal(`.home__data, .home__img,
.about__data, .about__img,
.services__content, .menu__content,
.app__data, .app__img,
.contact__data, .contact__button,
.footer__content`,{
interval: 200
})