-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
378 lines (312 loc) · 10.3 KB
/
index.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
let productList = [
{
name: "Adidas Superstar",
desc: "Giày cổ điển với thiết kế đặc trưng, phần mũi giày có hình vỏ sò nổi bật và chất liệu da cao cấp.",
images: [
"images/superstar1.avif",
"images/superstar2.avif",
"images/superstar3.avif"
],
price: 2000000
},
{
name: "Yeezy 350",
desc: "Giày thể thao phong cách và thoải mái, nổi tiếng với chất liệu Primeknit và đế Boost siêu êm.",
images: [
"images/yz1.avif",
"images/yz2.avif",
"images/yz3.avif"
],
price: 5000000
},
{
name: "Adidas Gazelle",
desc: "Giày thể thao cổ điển với chất liệu da lộn mềm mại và đế cao su chắc chắn, mang lại sự êm ái và phong cách.",
images: [
"images/gazelle1.avif",
"images/gazelle2.avif",
"images/gazelle3.avif"],
price: 1800000
},
{
name: "Cloudfoam",
desc: "Giày chạy bộ nhẹ nhàng và thoải mái với công nghệ Cloudfoam đem lại cảm giác êm ái trong mỗi bước.",
images: [
"images/cloudfoam1.avif",
"images/cloudfoam2.avif",
"images/cloudfoam3.avif"],
price: 1200000
},
{
name: "Ultra Boost 1.0",
desc: "Giày chạy bộ với công nghệ đệm Boost tiên tiến, cung cấp sự đàn hồi và thoải mái tối đa khi chạy.",
images: [
"images/ultraboost1.avif",
"images/ultraboost2.avif",
"images/ultraboost3.avif"],
price: 3500000
},
{
name: "Adidas Forum 84",
desc: "Giày thể thao retro với phong cách độc đáo, phần cổ giày cao và đế ngoài bền bỉ.",
images: [
"images/forum1.avif",
"images/forum2.avif",
"images/forum3.avif"],
price: 2200000
},
{
name: "Adidas Rivalry",
desc: "Giày bóng rổ với thiết kế mạnh mẽ, phần đế ngoài chắc chắn và hỗ trợ tốt cho các động tác nhanh.",
images: [
"images/rivalry1.avif",
"images/rivalry2.avif",
"images/rivalry3.avif"],
price: 2300000
},
{
name: "Nike Air Force 1",
desc: "Giày thể thao kinh điển với thiết kế bền bỉ, đế Air giúp giảm chấn và đem lại sự thoải mái trong suốt ngày dài.",
images: [
"images/af1.webp",
"images/af2.webp",
"images/af3.webp"],
price: 2500000
},
{
name: "Nike Air Max 270",
desc: "Giày thể thao với đệm khí lớn ở gót chân, mang lại sự thoải mái và phong cách hiện đại.",
images: [
"images/max1.webp",
"images/max2.webp",
"images/max3.webp"],
price: 3000000
},
{
name: "Nike Dunk Low",
desc: "Giày thể thao phong cách đường phố, với thiết kế đế phẳng và nhiều màu sắc khác nhau.",
images: [
"images/dunklow1.webp",
"images/dunklow2.webp",
"images/dunklow3.webp"],
price: 2700000
},
{
name: "Nike Blazer Mid '77",
desc: "Giày thể thao cổ cao với thiết kế retro, phần da bền và đế cao su giúp bám đường tốt.",
images: [
"images/blazer1.webp",
"images/blazer2.webp",
"images/blazer3.webp"],
price: 2400000
},
{
name: "Puma Suede Classic",
desc: "Giày thể thao với chất liệu da lộn, đế ngoài cao su và phong cách cổ điển.",
images: [
"images/suede1.avif",
"images/suede2.avif",
"images/suede3.avif"],
price: 1600000
},
{
name: "Puma RS-X3",
desc: "Giày thể thao với thiết kế đậm chất công nghệ, phần đế dày và các chi tiết nhiều màu sắc.",
images: [
"images/rsx1.avif",
"images/rsx2.avif",
"images/rsx3.avif"],
price: 2800000
},
{
name: "Puma Cali",
desc: "Giày thể thao phong cách California, với phần đế thấp và thiết kế đơn giản nhưng nổi bật.",
images: [
"images/cali1.avif",
"images/cali2.avif",
"images/cali3.avif"],
price: 1900000
},
{
name: "New Balance 574",
desc: "Giày thể thao với thiết kế đa năng, đế EVA và công nghệ ENCAP cho sự thoải mái và hỗ trợ tốt.",
images: [
"images/nb1.webp",
"images/nb2.webp",
"images/nb3.webp"],
price: 2100000
},
{
name: "Converse Chuck Taylor All Star",
desc: "Giày thể thao kinh điển với thiết kế bất hủ, phần vải bền và đế cao su chắc chắn.",
images: [
"images/converse1.webp",
"images/converse2.webp",
"images/converse3.webp"],
price: 1400000
}
];
document.addEventListener('DOMContentLoaded', () => {
if (!document.cookie.includes("cart")) {
document.cookie = "cart=[]";
}
document.cookie = "sanpham={}";
productList.forEach(p => add_item_list(p));
productList.slice(0,7).forEach(p => addHotItemList(p));
});
function addHotItemList(item) {
// Create a div element
const div = document.createElement('div');
div.id = 'hot-product';
div.className = 'hot-product-item';
// Create an img element
const img = document.createElement('img');
img.src = item.images[0];
img.alt = item.images[0];
// Create an h3 element
const h3 = document.createElement('h3');
h3.textContent = item.name;
// Create a p element for the description
const descriptionP = document.createElement('p');
descriptionP.textContent = item.desc;
const addToCartBtn = document.createElement('button');
addToCartBtn.className = 'add-to-cart-btn';
addToCartBtn.textContent = 'Bỏ Vào Giỏ';
addToCartBtn.addEventListener("click", () => {
let cart;
try {
let cartString = document.cookie.split(";")[1].split("=")[1];
cart = JSON.parse(cartString);
cart.push(item);
} catch (error) {
let cartString = document.cookie.split(";")[0].split("=")[1];
cart = JSON.parse(cartString);
cart.push(item);
}
document.cookie = "cart=" + JSON.stringify(cart);
});
// Create a p element for the price
const priceP = document.createElement('p');
priceP.className = 'gia';
priceP.textContent = item.price;
// Create a button element
const button = document.createElement('button');
button.className = 'xem-chi-tiet';
button.textContent = 'Xem chi Tiết';
button.addEventListener("click", () => {
document.cookie = "sanpham=" + JSON.stringify(item);
window.location.href = "sanpham.html";
})
div.addEventListener("mouseover", () => {
img.style.transform = "scale(1.2)";
addToCartBtn.style.opacity = "1";
});
div.addEventListener("mouseout", () => {
img.style.transform = "scale(1)";
addToCartBtn.style.opacity = "0";
});
// Append the elements to the div
div.appendChild(img);
div.appendChild(h3);
div.appendChild(descriptionP);
div.appendChild(addToCartBtn);
div.appendChild(priceP);
div.appendChild(button);
// Append the div to the body or any other container
document.getElementById("hot-products-list").appendChild(div);
}
function add_item_list(item) {
// Create the product list container
// Create the product item container
var productItem = document.createElement('div');
productItem.className = 'product-item';
// Create and append the image element
var img = document.createElement('img');
img.src = item.images[0];
img.alt = 'Image ';
productItem.appendChild(img);
productItem.addEventListener("mouseover", () => {
img.style.transform = "scale(1.2)";
addToCartBtn.style.opacity = "1";
});
productItem.addEventListener("mouseout", () => {
img.style.transform = "scale(1)";
addToCartBtn.style.opacity = "0";
});
// Create and append the h3 element
var h3 = document.createElement('h3');
h3.textContent = item.name;
productItem.appendChild(h3);
var price = document.createElement('strong');
price.textContent = item.price + " VNĐ";
productItem.appendChild(price);
// Create and append the paragraph element
var p = document.createElement('p');
p.textContent = item.desc;
productItem.appendChild(p);
// Create and append the "Add to Cart" button
var addToCartBtn = document.createElement('button');
addToCartBtn.className = 'add-to-cart-btn';
addToCartBtn.textContent = 'Bỏ Vào Giỏ';
productItem.appendChild(addToCartBtn);
addToCartBtn.addEventListener("click", () => {
let cart;
try {
let cartString = document.cookie.split(";")[1].split("=")[1];
cart = JSON.parse(cartString);
cart.push(item);
} catch (error) {
let cartString = document.cookie.split(";")[0].split("=")[1];
cart = JSON.parse(cartString);
cart.push(item);
}
document.cookie = "cart=" + JSON.stringify(cart);
});
// Create and append the "Mua Ngay" button
var chiTietBtn = document.createElement('button');
chiTietBtn.textContent = 'Xem chi tiết';
chiTietBtn.addEventListener("click", () => {
document.cookie = "sanpham=" + JSON.stringify(item);
window.location.href = "sanpham.html";
})
productItem.appendChild(chiTietBtn);
// Append the product list to the body (or any other container)
document.getElementById("product_lists_item").appendChild(productItem);
}
document.addEventListener('DOMContentLoaded', () => {
const images = [
'images/superstar1.avif',
'images/yz1.avif',
'images/af1.webp',
'images/blazer1.webp',
'images/nb1.webp',
'images/rsx1.avif',
'images/converse1.webp'
];
let currentIndex = 0;
const sliderImage = document.getElementById('slider-image');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
function showImage(index) {
sliderImage.src = images[index];
}
setInterval(() => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
}, 2000);
prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : images.length - 1;
showImage(currentIndex);
});
nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex < images.length - 1) ? currentIndex + 1 : 0;
showImage(currentIndex);
});
// Initial image
showImage(currentIndex);
});
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}