-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
192 lines (148 loc) · 6.61 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
document.addEventListener("DOMContentLoaded", function () {
const carousels = document.querySelectorAll(".carousel-container");
carousels.forEach(carousel => {
const productContainer = carousel.querySelector(".product-container");
const prevButton = carousel.querySelector(".prev");
const nextButton = carousel.querySelector(".next");
const scrollAmount = 350;
const scrollSpeed = 15;
const scrollStep = 20;
function smoothScroll(container, direction) {
let step = 0;
const interval = setInterval(() => {
container.scrollBy({ left: direction * scrollStep, behavior: "auto" });
step += scrollStep;
if (step >= scrollAmount) {
clearInterval(interval);
}
}, scrollSpeed);
}
prevButton.addEventListener("click", () => {
smoothScroll(productContainer, -1);
});
nextButton.addEventListener("click", () => {
smoothScroll(productContainer, 1);
});
});
});
document.addEventListener("DOMContentLoaded", function () {
const shoeImage = document.getElementById("shoeImage");
const colorOptions = document.querySelectorAll(".color-option");
const shoeColors = {
green: "https://assets.codepen.io/4164355/shoes.png",
blue: "https://assets.codepen.io/4164355/shoes-blue.png",
red: "https://assets.codepen.io/4164355/shoes-red.png"
};
colorOptions.forEach(option => {
option.addEventListener("click", function () {
const selectedColor = this.getAttribute("data-color");
shoeImage.src = shoeColors[selectedColor] || shoeColors.green;
});
});
});
document.addEventListener("DOMContentLoaded", function () {
const buttons = document.querySelectorAll(".botaoProdutos");
buttons.forEach(button => {
button.addEventListener("click", function (event) {
event.preventDefault();
const productCard = button.closest(".card");
const productName = productCard.querySelector("h2").innerText;
const productPrice = parseFloat(productCard.querySelector(".price").innerText.replace('R$', '').replace(',', '.'));
const productImage = productCard.querySelector("img").src;
addToCart(productName, productPrice, productImage);
});
});
});
function addToCart(name, price, image) {
let cart = JSON.parse(localStorage.getItem("cart")) || [];
const itemIndex = cart.findIndex(item => item.name === name);
if (itemIndex > -1) {
cart[itemIndex].quantity++;
} else {
cart.push({ name, price, image, quantity: 1 });
}
localStorage.setItem("cart", JSON.stringify(cart));
updateCartDisplay(); // Atualiza o carrinho na interface
showCartMessage("O tênis foi adicionado ao carrinho!"); // Exibe a mensagem
}
document.addEventListener("DOMContentLoaded", function () {
const brandLogos = document.querySelectorAll(".imgsMarcas img");
const allSections = document.querySelectorAll(".products");
const sectionsMap = {}; // Mapeamento para acesso rápido
// Criando um mapeamento de seções para evitar percorrer toda a lista sempre
allSections.forEach(section => {
const sectionTitle = section.querySelector("h2").textContent.toLowerCase().trim();
sectionsMap[sectionTitle] = section;
});
brandLogos.forEach(logo => {
logo.addEventListener("click", function () {
const selectedBrand = this.alt.toLowerCase().trim();
console.log("Marca selecionada:", selectedBrand); // Debug para ver o nome da marca
// Corrigir nomes que podem estar diferentes no HTML
const brandMapping = {
"nike": "nike",
"puma": "puma",
"adidas": "adidas",
"jordan": "jordan",
"vans": "vans",
"newbalance": "new balance",
"new balance": "new balance",
"nb": "new balance" // Adicionado para corrigir a seleção errada
};
const normalizedBrand = brandMapping[selectedBrand] || selectedBrand;
console.log("Marca normalizada:", normalizedBrand); // Debug
// Oculta todas as seções
allSections.forEach(section => section.style.display = "none");
// Exibe apenas a seção correspondente
if (sectionsMap[normalizedBrand]) {
const selectedSection = sectionsMap[normalizedBrand];
selectedSection.style.display = "flex";
selectedSection.style.flexDirection = "column";
// Transforma em grid
const productContainer = selectedSection.querySelector(".product-container");
productContainer.style.display = "grid";
productContainer.style.gridTemplateColumns = "repeat(auto-fill, minmax(300px, 1fr))";
productContainer.style.gap = "20px";
productContainer.style.overflow = "visible";
// Esconde os botões do carrossel
selectedSection.querySelectorAll(".prev, .next").forEach(button => button.style.display = "none");
} else {
console.warn(`Nenhuma seção encontrada para a marca: ${selectedBrand}`);
}
});
});
// Resetando exibição inicial como carrossel ao recarregar
function resetDisplay() {
allSections.forEach(section => {
section.style.display = "flex";
section.style.flexDirection = "column";
const productContainer = section.querySelector(".product-container");
const carouselButtons = section.querySelectorAll(".prev, .next");
productContainer.style.display = "flex";
productContainer.style.overflowX = "auto";
carouselButtons.forEach(button => button.style.display = "block");
});
}
resetDisplay();
});
/*menu responsivo */
function toggleMenu() {
var menu = document.getElementById("menu");
menu.classList.toggle("active");
}
let btnMenu = document.getElementById('btn-menu')
let menu = document.getElementById('menu-mobile')
let overlay = document.getElementById('overlay-menu')
btnMenu.addEventListener('click', ()=>{
menu.classList.add('abrir-menu')
})
menu.addEventListener('click', ()=>{
menu.classList.remove('abrir-menu')
})
overlay.addEventListener('click', ()=>{
menu.classList.remove('abrir-menu')
})
function toggleMenu() {
var menu = document.querySelector(".menu-mobile");
menu.classList.toggle("active");
}