-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (30 loc) · 1.07 KB
/
script.js
File metadata and controls
36 lines (30 loc) · 1.07 KB
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
const cards = document.querySelectorAll('.card');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
let currentIndex = 0;
function showCard(index) {
cards.forEach((card, i) => {
if (i === index) {
card.style.transform = 'translateX(0)';
card.style.opacity = '1';
} else {
card.style.transform = 'translateX(100%)';
card.style.opacity = '0';
}
});
}
// Add an event listener to the third image for redirection
const thirdImage = cards[2].querySelector('img'); // Assuming the third image is in the third card
thirdImage.addEventListener('click', () => {
window.location.href = 'https://www.google.com';
});
prevBtn.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + cards.length) % cards.length;
showCard(currentIndex);
});
nextBtn.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % cards.length;
showCard(currentIndex);
});
// Initial setup
showCard(currentIndex);