-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard-animation.js
76 lines (65 loc) · 2 KB
/
card-animation.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
let lastClickedTab = 0;
document.querySelectorAll('.card').forEach((card, index) => {
const tab = card.querySelector('.tab');
tab.addEventListener('click', function () {
if (lastClickedTab == tab) return;
const cards = document.querySelectorAll('.card');
const isBack = card.classList.contains('active');
if (isBack) card.classList.remove('active');
cards.forEach((otherCard, otherIndex) => {
console.log(otherIndex);
const isActive = otherCard.classList.contains('active');
if (isBack && otherIndex > index && isActive) {
otherCard.classList.remove('active');
otherCard.style.zIndex = `calc(1000 - var(--i))`;
console.log("im flipping this card up");
} else if (!isBack && otherIndex < index && !isActive) {
otherCard.classList.add('active');
console.log("im flipping this card down")
} else {
console.log("im doing nothing")
}
});
const deck = document.querySelector('.deck');
deck.classList.add('flipping');
setTimeout(() => {
deck.classList.remove('flipping');
cards.forEach((card, index) => {
console.log(index);
card.style.zIndex = `calc(100 - var(--i))`;
});
}, 750);
lastClickedTab = tab;
});
});
window.addEventListener('load', function () {
const cards = document.querySelectorAll('.card');
let delay = 0;
for (let i = 0; i < 3; i++) {
const card = cards[i];
setTimeout(() => {
card.classList.add('active');
const deck = document.querySelector('.deck');
deck.classList.add('flipping');
setTimeout(() => {
deck.classList.remove('flipping');
}, 2000);
}, delay);
delay += 500;
}
setTimeout(() => {
delay = 500;
for (let i = 2; i >= 0; i--) {
const card = cards[i];
setTimeout(() => {
card.classList.remove('active');
const deck = document.querySelector('.deck');
deck.classList.add('flipping');
setTimeout(() => {
deck.classList.remove('flipping');
}, 2000);
}, delay);
delay += 500;
}
}, 2000);
});