forked from Dogfalo/materialize
-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathcards.ts
46 lines (38 loc) · 1.59 KB
/
cards.ts
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
export class Cards {
static Init() {
document.addEventListener("DOMContentLoaded", () => {
document.body.addEventListener('click', e => {
const trigger = <HTMLElement>e.target;
const card: HTMLElement = trigger.closest('.card');
if (!card) return;
const cardReveal = <HTMLElement|null>Array.from(card.children).find(elem => elem.classList.contains('card-reveal'));
if (!cardReveal) return;
const initialOverflow = getComputedStyle(card).overflow;
// Close Card
const closeArea = cardReveal.querySelector('.card-reveal .card-title');
if (trigger === closeArea || closeArea.contains(trigger)) {
const duration = 225;
cardReveal.style.transition = `transform ${duration}ms ease`; //easeInOutQuad
cardReveal.style.transform = 'translateY(0)';
setTimeout(() => {
cardReveal.style.display = 'none';
card.style.overflow = initialOverflow;
}, duration);
};
// Reveal Card
const activators = card.querySelectorAll('.activator');
activators.forEach(activator => {
if (trigger === activator || activator.contains(trigger)) {
card.style.overflow = 'hidden';
cardReveal.style.display = 'block';
setTimeout(() => {
const duration = 300;
cardReveal.style.transition = `transform ${duration}ms ease`; //easeInOutQuad
cardReveal.style.transform = 'translateY(-100%)';
}, 1);
}
});
});
});
}
}