-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
91 lines (72 loc) · 2.59 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
function showPopup() {
document.getElementById('popup').style.display = 'flex';
}
function closePopup() {
document.getElementById('popup').style.display = 'none';
}
function logout() {
closePopup();
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('popup').addEventListener('click', function(event) {
if (event.target === this) {
closePopup();
}
});
document.querySelector('a[href="#home"]').addEventListener('click', function(event) {
event.preventDefault();
document.getElementById('home').scrollIntoView();
});
let banners = document.querySelectorAll('.banner');
let currentBannerIndex = 0;
function showBanner(index) {
banners.forEach((banner, i) => {
if (i === index) {
banner.style.display = 'block';
} else {
banner.style.display = 'none';
}
});
}
function switchBanner() {
currentBannerIndex = (currentBannerIndex + 1) % banners.length;
showBanner(currentBannerIndex);
}
showBanner(currentBannerIndex);
setInterval(switchBanner, 2000);
let reviewIndex = 0;
const reviews = document.querySelectorAll('.review-box');
function showReview(index) {
reviews.forEach(review => review.style.transform = `translateX(${-index * 100}%)`);
}
function nextReview() {
reviewIndex = (reviewIndex + 1) % reviews.length;
showReview(reviewIndex);
}
setInterval(nextReview, 3000);
const addToCartButtons = document.querySelectorAll('.buy-button');
addToCartButtons.forEach(button => {
button.addEventListener('click', function(event) {
event.preventDefault();
const addedToCartMessage = document.createElement('div');
addedToCartMessage.textContent = 'Added to cart';
addedToCartMessage.classList.add('added-to-cart-message');
document.body.appendChild(addedToCartMessage);
setTimeout(() => {
addedToCartMessage.remove();
}, 3000);
});
});
const productImages = document.querySelectorAll('.product img');
const productImage = document.querySelectorAll('.product-center img');
productImages.forEach(image => {
image.addEventListener('click', function(event) {
window.location.href = 'product.html';
});
});
productImage.forEach(image => {
image.addEventListener('click', function(event) {
window.location.href = 'product.html';
});
});
});