-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_lower-third-template.html
206 lines (179 loc) · 10.7 KB
/
example_lower-third-template.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html>
<!--CasparCG-Lottie-Template - https://github.com/jdoppelp/CasparCG-Lottie-Template - by jdoppelp @https://github.com/jdoppelp - 2023-04-21 -->
<head>
<meta charset='utf-8'>
<title>Lottie Template 01</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<style>
html {
overflow: hidden;
}
body {
margin: 0;
width: 100vw;
}
p {
font-size: 30px;
margin: 0px;
margin-left: 20px;
color: white
}
h1 {
margin-left: 20px;
color: white
}
</style>
</head>
<body id="animation">
<script src='lottie.js'></script>
<!--Animations-Script-->
<script>
"use strict"
//Paste Lottie File .JSON Code
let lottieTemplate = {"v":"5.9.0","fr":25,"ip":0,"op":100,"w":1920,"h":1080,"nm":"LowerThird_Simple_Ver03","ddd":0,"assets":[{"id":"image_0","w":824,"h":914,"u":"images/","p":"img_0.png","e":0}],"fonts":{"list":[{"origin":0,"fPath":"./fonts/OpenSans/OpenSans-Regular.ttf","fClass":"","fFamily":"OpenSans-Regular","fWeight":"","fStyle":"Regular","fName":"OpenSans-Regular","ascent":75.9994506835938},{"origin":0,"fPath":"./fonts/OpenSans/OpenSans-SemiBold.ttf","fClass":"","fFamily":"OpenSans-SemiBold","fWeight":"","fStyle":"SemiBold","fName":"OpenSans-SemiBold","ascent":75.9994506835938}]},"layers":[{"ddd":0,"ind":1,"ty":2,"nm":"img_0.png","cl":"png","parent":5,"refId":"image_0","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[-779.6,287.631,0],"ix":2,"l":2},"a":{"a":0,"k":[412,457,0],"ix":1,"l":2},"s":{"a":0,"k":[12,12,100],"ix":6,"l":2}},"ao":0,"ip":0,"op":1125,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Circle","parent":5,"sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[-781,291,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[13,13,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[1080,1080],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Elliptischer Pfad 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"fl","c":{"a":0,"k":[0.894117706897,0.87450986376,0.854902020623,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fläche 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transformieren"}],"nm":"Ellipse 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":1125,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":5,"nm":"_firstLine","parent":5,"sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[-671,283,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"t":{"d":{"k":[{"s":{"s":60,"f":"OpenSans-SemiBold","t":"Name Nachname","ca":0,"j":0,"tr":0,"lh":72,"ls":0,"fc":[0.212,0.212,0.212]},"t":0}]},"p":{},"m":{"g":1,"a":{"a":0,"k":[0,0],"ix":2}},"a":[]},"ip":0,"op":750.750750750751,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":5,"nm":"_secondLine","parent":5,"sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[-671,334.9,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"t":{"d":{"k":[{"s":{"s":40,"f":"OpenSans-Regular","t":"Funktion Arbeit Beruf","ca":0,"j":0,"tr":0,"lh":48,"ls":0,"fc":[0.212,0.212,0.212]},"t":0}]},"p":{},"m":{"g":1,"a":{"a":0,"k":[0,0],"ix":2}},"a":[]},"ip":0,"op":750.750750750751,"st":0,"bm":0},{"ddd":0,"ind":5,"ty":4,"nm":"BG","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":1,"k":[{"i":{"x":0.307,"y":1},"o":{"x":0.66,"y":0},"t":0,"s":[-166,540,0],"to":[187.667,0,0],"ti":[-187.667,0,0]},{"i":{"x":0.307,"y":0.307},"o":{"x":0.333,"y":0.333},"t":47,"s":[960,540,0],"to":[0,0,0],"ti":[0,0,0]},{"i":{"x":0.883,"y":1},"o":{"x":0.887,"y":0},"t":75,"s":[960,540,0],"to":[-187.667,0,0],"ti":[187.667,0,0]},{"t":92,"s":[-166,540,0]}],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[100,100,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[1008,166],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":20,"ix":4},"nm":"Rechteckpfad: 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"fl","c":{"a":0,"k":[0.831372608858,0.705882352941,0.513725490196,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fläche 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-374,289],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transformieren"}],"nm":"Rechteck 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":750,"st":0,"bm":0}],"markers":[{"tm":0,"cm":"Start","dr":50},{"tm":50,"cm":"Still","dr":25},{"tm":75,"cm":"Stop","dr":18}]}
let playStatus = ""
let nextCount = 1
let showInfo = false
let currentSegment
let currentSegmentFrames
let animReady
let animation
let newAnimation
let stopExist = false
//add font-face from data.json //Credits to HeineFro @https://github.com/HeineFro
const addFont = (fam, path) => {
let newFont = document.createElement('style')
newFont.appendChild(document.createTextNode(`\
@font-face {\
font-family: ${fam};\
src: url('${path}');\
}\
`));
document.head.appendChild(newFont);
}
//fix Marker Name
lottieTemplate.markers.forEach((marker) => {
let name = marker.cm
marker.cm = "name:" + name.toLowerCase()
})
function update(rawData) {
let lottieTemplateNew = { ...lottieTemplate };
if (rawData) {
if (rawData.startsWith("<templateData>")) {
let title = document.createElement("h1")
title.appendChild(document.createTextNode("Please send Data as JSON"))
document.body.appendChild(title)
console.error("Data must be send as JSON")
} else {
let parsed = JSON.parse(rawData)
for (let key of Object.keys(parsed)) {
if (key == "_templateInfo") showInfo = true
lottieTemplateNew.layers.forEach((layer) => {
if (layer.nm == key) {
layer.t.d.k[0].s.t = parsed[key]
}
})
}
}
}
if (playStatus == "") {
animation = bodymovin.loadAnimation({
container: document.getElementById("animation"),
renderer: "svg",
loop: false,
autoplay: false,
animationData: lottieTemplateNew,
})
let fonts = animation.renderer.data.fonts.list;
for (const font in fonts) {
let family = fonts[font].fFamily
let fontPath = fonts[font].fPath
if (fontPath !== '') {
addFont(family, fontPath)
}
}
animReady = new Promise((resolve, reject) => {
animation.addEventListener("loaded_images", function () {
console.log("READY")
resolve("ready")
})
})
animation.addEventListener("enterFrame", () => {
for (let marker of lottieTemplate.markers) {
if (marker.cm == "name:" + currentSegment) {
currentSegmentFrames = marker.tm
}
}
const currentFrame = animation.currentFrame + currentSegmentFrames
console.log(`Current Frame: ${currentFrame}`);
})
}
if (playStatus == "play") {
animation.destroy()
animation = bodymovin.loadAnimation({
container: document.getElementById("animation"),
renderer: "svg",
loop: false,
autoplay: false,
animationData: lottieTemplateNew,
})
for (let marker of lottieTemplateNew.markers) {
if (marker.cm == "name:" + currentSegment) {
animation.goToAndStop(marker.tm + marker.dr, true)
}
}
}
if (showInfo) info()
}
function play() {
animReady.then(() => {
animation.goToAndPlay("start", true)
playStatus = "play"
currentSegment = "start"
})
}
function load() {
animReady.then(() => {
animation.goToAndStop(0, true)
playStatus = "loadeed"
currentSegment = "start"
})
}
function stop() {
for (let marker of lottieTemplate.markers) {
if (marker.cm == "name:" + "stop") {
stopExist = true
}
}
if (stopExist) {
animation.goToAndPlay("stop", true)
} else {
animation.destroy()
}
playStatus = "stop"
}
function next() {
animation.goToAndPlay("next" + nextCount, true)
currentSegment = "next" + nextCount
nextCount++
}
function info() {
animation.destroy()
let title = document.createElement("h1")
title.appendChild(document.createTextNode("These are the names of your After-Effects layers starting with \"_\"."))
document.body.appendChild(title)
lottieTemplate.layers.forEach((layer) => {
if (layer.nm.startsWith("_")) {
let nameElement = document.createElement("p")
let text = document.createTextNode(layer.nm)
let br = document.createElement("br")
nameElement.appendChild(text)
document.body.appendChild(nameElement);
document.body.appendChild(br);
}
})
}
</script>
</body>
</html>