-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.js
78 lines (73 loc) · 1.79 KB
/
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
77
78
/**
* Shakes it up, down, left, right and rotates.
* @param {String} element Could be class, id, element etc.
*/
const shake = (element) => {
xMax = 20;
anime({
targets: element,
easing: 'easeInOutSine',
translateX: [ xMax * -2, xMax*2, xMax/-2, xMax/2, 0 ],
translateY: [ xMax * -2, xMax*2, xMax/-2, xMax/2, 0 ],
rotate: [xMax * -1, xMax, xMax/-2, xMax/2, 0],
duration: 500,
})
}
/**
* Shakes left and right.
* @param {String} element Could be class, id, element etc.
*/
const shakeLeftRigt = (element) => {
xMax = 20;
anime({
targets: element,
easing: 'easeInOutSine',
translateX: [ xMax * -2, xMax*2, xMax/-2, xMax/2, 0 ],
translateY: [ xMax * -2, xMax*2, xMax/-2, xMax/2, 0 ],
duration: 500,
})
}
/**
* Makes element go up and down
* @param {String} element Could be class, id, element etc.
*/
const upAndDown = (element) => {
xMax = 20;
anime({
targets: element,
easing: 'easeInOutSine',
translateY: [ xMax ],
direction: 'alternate',
loop: true,
duration: 200
})
}
/**
* Rotates back and fourth
* @param {String} element Could be class, id, element etc.
*/
const rotateAnimation = (element) => {
xMax = 2;
anime({
targets: element,
easing: 'easeInOutSine',
rotate: [ xMax, xMax*-1 ],
direction: 'alternate',
loop: true,
duration: 1000
})
}
/**
* Flips around the y-axis.
* @param {String} element Could be class, id, element etc.
*/
const flipAnimation = (element) => {
anime({
delay: 2000,
targets: element,
easing: 'easeInOutQuad',
direction: 'alternate',
rotateY: [{ value: "180deg", duration: 700 }],
loop: 1,
})
}