-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
124 lines (114 loc) · 4.21 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"use strict";
/*===== loader ===== */
const loader = document.querySelector(".loader");
window.addEventListener("load", () => (loader.style.display = "none"));
/*===== TOGGLE CARRITO ===== */
const iconoCarrito = document.querySelector(".iconos__carrito");
const carrito = document.querySelector(".carrito");
const iconoClose = document.querySelector(".carrito__close");
const agregadoExitosamente = document.querySelector(".agregadoExitosamente");
const bodyEvento = document.querySelector("body");
const toggleCard = () => {
iconoCarrito.addEventListener("click", () => {
carrito.classList.toggle("active");
agregadoExitosamente.classList.add("left");
bodyEvento.classList.add('active')
});
iconoClose.addEventListener("click", () => {
carrito.classList.remove("active");
agregadoExitosamente.classList.remove("left");
bodyEvento.classList.remove('active')
});
};
toggleCard();
/*===== TOGGLE MENU ===== */
const iconoMenu = document.querySelector(".iconos__menu");
const iconoCloseMenu = document.querySelector(".navegacion__close");
const navegacion = document.querySelector(".navegacion__lista");
const navegacionLinks = document.querySelectorAll(".navegacion__link");
const toggleNavegacion = () => {
iconoMenu.addEventListener("click", () => {
navegacion.classList.toggle("active");
bodyEvento.classList.add('active')
});
iconoCloseMenu.addEventListener("click", () => {
navegacion.classList.remove("active");
bodyEvento.classList.remove('active')
});
navegacionLinks.forEach((item) => {
item.addEventListener("click", () => {
navegacion.classList.remove("active");
bodyEvento.classList.remove('active')
});
});
};
toggleNavegacion();
/*===== TOGGLE MODO ===== */
const iconosModo = document.querySelector(".iconos__modo");
const body = document.querySelector("body");
const toggleModo = () => {
iconosModo.addEventListener("click", () => {
iconosModo.classList.toggle("active");
body.classList.toggle("oscuro");
if (!body.classList.contains("oscuro")) {
localStorage.setItem("modo", "claro");
} else {
localStorage.setItem("modo", "oscuro");
}
});
let getModo = localStorage.getItem("modo");
if (getModo === "oscuro") {
iconosModo.classList.toggle("active");
body.classList.toggle("oscuro");
} else {
iconosModo.classList.remove("active");
body.classList.remove("oscuro");
}
};
toggleModo();
/*===== EFECTO DEL SCROLL ===== */
const header = document.querySelector(".header");
const efectoScroll = () => {
window.addEventListener("scroll", () => {
let valorScroll = window.scrollY;
if (valorScroll > 50) {
header.style.boxShadow = "var(--box-shadow)";
header.style.background = "var(--container-color)";
} else {
header.style.boxShadow = "none";
header.style.background = "none";
}
});
};
efectoScroll();
/*===== SHOW SCROLL UP ===== */
const sections = document.querySelectorAll("section[id]");
function scrollActive() {
const scrollY = window.pageYOffset;
sections.forEach((seccion) => {
const sectionHeight = seccion.offsetHeight,
sectionTop = seccion.offsetTop - 58,
sectionId = seccion.getAttribute("id");
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
document
.querySelector(`.navegacion__lista a[href*= ${sectionId}]`)
.classList.add("active");
} else {
document
.querySelector(".navegacion__lista a[href*=" + sectionId + "]")
.classList.remove("active");
}
});
}
window.addEventListener("scroll", scrollActive);
/*===== SHOW SCROLL UP ===== */
function scrollUp() {
const scrollUp = document.querySelector("#scroll-up");
// When the scroll is higher than 350 viewport height, add the show-scroll class to the a tag with the scroll-top class
if (this.scrollY >= 350) {
scrollUp.classList.add("show-scroll");
} else {
scrollUp.classList.remove("show-scroll");
}
}
window.addEventListener("scroll", scrollUp);