-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpc.js
149 lines (132 loc) · 4.18 KB
/
pc.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* SHOW MENU */
const navMenu = document.getElementById("nav-menu"),
navToggle = document.getElementById("nav-toggle"),
navClose = document.getElementById("nav-close");
/* MENU SHOW */
/* Validate if constant exists */
if (navToggle) {
navToggle.addEventListener("click", () => {
navMenu.classList.add("show-menu");
});
}
/* MENU HIDDEN */
/* Validate if constant exists */
if (navClose) {
navClose.addEventListener("click", () => {
navMenu.classList.remove("show-menu");
});
}
/* REMOVE MENU MOBILE */
const navLink = document.querySelectorAll(".nav__link");
function linkAction() {
const navMenu = document.getElementById("nav-menu");
// When we click on each nav__link, we remove the show-menu class
navMenu.classList.remove("show-menu");
}
navLink.forEach((n) => n.addEventListener("click", linkAction));
/* HOME SWIPER */
let homeSwiper = new Swiper(".home-swiper", {
spaceBetween: 30,
loop: "true",
pagination: {
el: ".swiper-pagination",
clickable: true
}
});
/* change body's background color */
let root = document.documentElement;
homeSwiper.on("transitionEnd", function (e) {
if (this.activeIndex == 1) {
root.style.setProperty(
"--body-color",
"linear-gradient(to right, #2E0916, #200A2B)"
);
root.style.setProperty("--sub", "#ff5b79");
root.style.setProperty("--title-color", "#ffffff");
root.style.setProperty(
"--container-color",
"linear-gradient(136deg, #2E0916, #200A2B)"
);
}
if (this.activeIndex == 2) {
root.style.setProperty(
"--body-color",
"linear-gradient(to right, #E8CAFB, #6A4FB6)"
);
root.style.setProperty("--sub", "#303056");
root.style.setProperty("--title-color", "#303056");
root.style.setProperty(
"--container-color",
"linear-gradient(136deg, #E8CAFB, #6A4FB6)"
);
}
if (this.activeIndex == 3) {
root.style.setProperty(
"--body-color",
"linear-gradient(to right, #5B874B, #0C3720)"
);
root.style.setProperty("--sub", "#ffffff");
root.style.setProperty("--title-color", "#ffffff");
root.style.setProperty(
"--container-color",
"linear-gradient(136deg, #5B874B, #0C3720)"
);
}
});
/* CHANGE BACKGROUND HEADER */
function scrollHeader() {
const header = document.getElementById("header");
// When the scroll is greater than 50 viewport height, add the scroll-header class to the header tag
if (this.scrollY >= 50) header.classList.add("scroll-header");
else header.classList.remove("scroll-header");
}
window.addEventListener("scroll", scrollHeader);
/* NEW SWIPER */
let newSwiper = new Swiper(".new-swiper", {
centeredSlides: true,
slidesPerView: "auto",
loop: "true",
spaceBetween: 16
});
/* SCROLL SECTIONS ACTIVE LINK */
const sections = document.querySelectorAll("section[id]");
function scrollActive() {
const scrollY = window.pageYOffset;
sections.forEach((current) => {
const sectionHeight = current.offsetHeight,
sectionTop = current.offsetTop - 58,
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);
/* SHOW SCROLL UP */
function scrollUp() {
const scrollUp = document.getElementById("scroll-up");
// When the scroll is higher than 460 viewport height, add the show-scroll class to the a tag with the scroll-top class
if (this.scrollY >= 460) scrollUp.classList.add("show-scroll");
else scrollUp.classList.remove("show-scroll");
}
window.addEventListener("scroll", scrollUp);
/* SCROLL REVEAL ANIMATION */
const sr = ScrollReveal({
origin: "top",
distance: "60px",
duration: 2500,
delay: 400
// reset: true
});
sr.reveal(`.home-swiper, .new-swiper, .newsletter__container`);
sr.reveal(`.category__data, .trick__content, .footer__content`, {
interval: 100
});
sr.reveal(`.about__data, .discount__img`, { origin: "left" });
sr.reveal(`.about__img, .discount__data`, { origin: "right" });