-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
37 lines (33 loc) · 981 Bytes
/
index.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
import TWEEN from '@tweenjs/tween.js';
export default (propName, duration = 500, ease = TWEEN.Easing.Quadratic.Out) => {
const propNameTween = `${propName}Tween`;
return {
data() {
return {
[propNameTween]: this[propName],
};
},
watch: {
// watch when the prop changes and tween the tween prop from old to new
[propName](newValue, oldValue) {
new TWEEN.Tween({
number: oldValue,
})
.to({
number: newValue,
}, duration)
.easing(ease)
.onUpdate(tween => {
this[propNameTween] = tween.number;
})
.start();
animate();
},
},
};
};
function animate() {
if (TWEEN.update()) {
requestAnimationFrame(animate);
}
}