-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
125 lines (104 loc) · 2.97 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"use strict";
// DOM Variables
let body = document.querySelector("body");
let navigation = document.getElementById("navigation");
let backToTopButton = document.querySelector(".backToTopButton");
let reviews = document.getElementById("reviews");
let footer = document.querySelector("footer");
//Scroll
onScroll();
function onScroll() {
showToTop();
navbarScroll();
activateCurrentSection(home);
activateCurrentSection(reviews);
activateCurrentSection(classics);
activateCurrentSection(about);
activateCurrentSection(contact);
}
function navbarScroll() {
if (scrollY > 0) {
navigation.classList.add("scroll");
} else {
navigation.classList.remove("scroll");
}
}
// Active Sections
function activateCurrentSection(section) {
const targetLine = scrollY + innerHeight / 2;
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const linePassedTop = targetLine >= sectionTop;
const lineAboveHeight = targetLine <= sectionHeight + sectionTop;
const inSectionBoundaries = linePassedTop && lineAboveHeight;
const sectionId = section.getAttribute("id");
const menuElement = document.querySelector(`.menu a[href*=${sectionId}`);
menuElement.classList.remove("active");
if (inSectionBoundaries) {
menuElement.classList.add("active");
}
}
// Expandable Menu
function closeMenu() {
body.classList.remove("menu-expanded");
navigation.classList.remove("show");
}
function addEventsOnMenu() {
let menu_elements = document.querySelectorAll("#navigation .page-links a");
for (let elem of menu_elements) {
elem.addEventListener("click", closeMenu);
}
}
function openMenu() {
body.classList.add("menu-expanded");
navigation.classList.add("show");
addEventsOnMenu();
}
let closeMenuButton = document.querySelector(".closeMenuButton");
let openMenuButton = document.querySelector(".openMenuButton");
// Events
window.addEventListener("scroll", onScroll);
closeMenuButton.addEventListener("click", closeMenu);
openMenuButton.addEventListener("click", openMenu);
//ToTheTop Button
function showToTop() {
console.log(window.scrollY);
if (scrollY + innerHeight > innerHeight * 1.75) {
backToTopButton.classList.add("show");
if (scrollY + innerHeight > footer.offsetTop) {
backToTopButton.classList.add("onFooter");
} else {
backToTopButton.classList.remove("onFooter");
}
} else {
backToTopButton.classList.remove("show");
}
}
/* Swiper */
const swiper = new Swiper(".swiper", {
slidesPerView: "auto",
centeredSlides: true,
spaceBetween: 30,
mousewheel: true,
keyboard: true,
pagination: {
el: ".swiper-pagination",
clickable: true,
},
});
/* Scroll Reveal */
const scrollReveal = ScrollReveal({
origin: "left",
distance: "50px",
duration: 900,
});
scrollReveal.reveal(
`
#home header,#home .content,
#reviews header,#reviews .content,
#classics header,#classics .content .card,
#about header,#about .content,
#contact header,#contact .content,
footer`,
{ interval: 50 }
);