-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLottieComponent.js
58 lines (53 loc) · 2.24 KB
/
LottieComponent.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
class LottieClass {
constructor(_json) {
//Validación entrada tipo Objeto o JSON
if (typeof _json == 'object') {
_json = _json;
} else if (typeof _json == 'string') {
_json = JSON.parse(_json);
}
//Asignación de valores por entrada y Valores por defecto
this.Divid = _json.Divid?.toString() || 'newDivId';
this.Divclass = _json.Divclass?.toString() || 'content-NewDiv';
this.HostDiv = _json.HostDiv;
this.lottieId = _json.lottieId?.toString() || 'lottie-player';
this.lottieClass = _json.lottieClass?.toString() || 'newLottie-Player';
this.lottieSrc = _json.lottieSrc;
this.lottieSpeed = _json.lottieSpeed?.toString() || '1';
this.lottieLoop = _json.lottieLoop?.valueOf() || false;
this.lottieControls = _json.lottieControls?.valueOf() || false;
}
generarLottie() {
//Creación del Contenedor Lottie
var newDiv = document.createElement('div');
newDiv.id = this.Divid;
newDiv.className = this.Divclass;
//Agregación del Div al HostDiv
$(this.HostDiv).append(newDiv);
//Atributos css
$('#' + this.Divid).css({
"width": "100%",
"height": "100%",
});
//Creación del Lottie
var lottiePlayer = document.createElement('lottie-player');
lottiePlayer.id = this.lottieId;
lottiePlayer.className = this.lottieClass;
//Agregación del Lottie al HostDiv
$('#' + this.Divid).append(lottiePlayer);
//Asignación de atributos
$('#' + this.lottieId).attr({
"src": this.lottieSrc, //Fuente tipo JSON
"speed": this.lottieSpeed, //Velocidad de la animación
"loop": this.lottieLoop, //Si/No Bucle de la animación
"autoplay": true, //Si/No Reproduce al iniciar la función
"controls": this.lottieControls, //Si/No controles de la animación
"background": "transparent" //Color de fondo de la animación
});
//Atributos css (Default)
$('#' + this.lottieId).css({
"width": "100%",
"height": "100%",
});
}
}