-
Notifications
You must be signed in to change notification settings - Fork 3
/
polymate-behavior.html
100 lines (87 loc) · 2.39 KB
/
polymate-behavior.html
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="polymate-utils.html">
<script src="../bodymovin/build/player/lottie.js"></script>
<script>
(() => {
PolymateBehavior = function(superClass) {
return class extends PolymateUtils(superClass) {
/**
* @desc load the lottie animation using bodymovin player
* @param {Object} options
* @return {Void}
*/
initializeLottie(options) {
if (this.isEmpty(options)) return;
let _options = {
container: this.$.polymate,
renderer: options.renderer || 'svg',
loop: options.loop || false,
autoplay: options.autoplay || false,
autoloadSegments: options.autoloadSegments || false,
animationData: options.animationData,
path: options.path || '',
rendererSettings: options.rendererSettings || {}
};
return lottie.loadAnimation(_options);
}
/**
* @desc start the animation
* @return {Void}
*/
play() {
this.anim.play();
}
/**
* @desc stop the animation
* @return {Void}
*/
stop() {
this.anim.stop();
}
/**
* @desc pause the animation
* @return {Void}
*/
pause() {
this.anim.pause();
}
/**
* @desc set direction
* @param direction
* @return {Void}
*/
setDirection(direction) {
this.anim.setDirection(direction);
}
/**
* @desc reverse direction
* @return {Void}
*/
reverseDirection() {
this.setDirection(this.anim.playDirection * -1);
}
/**
* @desc is first frame
* @return {Boolean} isFirstFrame
*/
isFirstFrame() {
return this.anim.currentFrame === 0;
}
/**
* @desc is last frame
* @return {Boolean} isLastFrame
*/
isLastFrame() {
return this.anim.currentFrame === this.getLastFrame();
}
/**
* @desc get animation last frame
* @return {Number} lastFrame
*/
getLastFrame() {
return this.anim.totalFrames ? this.anim.totalFrames - 1 : false;
}
}
}
})();
</script>