-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhints.js
More file actions
57 lines (49 loc) · 1.59 KB
/
Copy pathhints.js
File metadata and controls
57 lines (49 loc) · 1.59 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Hints {
title = document.querySelector('.title');
instructions = document.querySelector('.instructions');
isAnimatingTexts = false;
textAnimationTimeout = null;
constructor() {}
show(duration) {
const initial = (from) => ({
opacity: 0,
transform: `translateY(${from === 'top' ? '-60px' : '60px'})`
});
const animate = {
opacity: 1,
transform: 'translateY(0px)'
};
if (!this.isAnimatingTexts) {
this.isAnimatingTexts = true;
this.title.animate([initial('top'), animate], {
duration: 300,
easing: 'ease-in-out',
fill: 'forwards'
});
this.instructions.animate([initial(), animate], {
duration: 300,
easing: 'ease-in-out',
fill: 'forwards'
});
} else {
clearTimeout(this.textAnimationTimeout);
}
if (!duration) return;
this.textAnimationTimeout = setTimeout(() => {
const titleAnim = this.title.animate([animate, initial('top')], {
duration: 300,
easing: 'ease-in-out',
fill: 'forwards'
});
this.instructions.animate([animate, initial()], {
duration: 300,
easing: 'ease-in-out',
fill: 'forwards'
});
titleAnim.onfinish = () => {
this.isAnimatingTexts = false;
};
}, duration);
}
}
export const hints = new Hints();