2019-06-19 15:26:00 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2020-06-19 15:11:03 +00:00
|
|
|
<title>Lottie-Web Perf</title>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<script src="/res/lottie.js" type="text/javascript" charset="utf-8"></script>
|
|
|
|
<style type="text/css" media="screen">
|
|
|
|
body {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
</style>
|
2019-06-19 15:26:00 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<main>
|
2019-07-08 18:48:12 +00:00
|
|
|
<div style="width:1000px;height:1000px" class=anim></div>
|
2019-06-19 15:26:00 +00:00
|
|
|
</main>
|
|
|
|
<script type="text/javascript" charset="utf-8">
|
|
|
|
(function () {
|
|
|
|
const PATH = '/res/lottie.json';
|
2019-07-08 18:48:12 +00:00
|
|
|
const RENDERER = 'svg';
|
2019-07-11 17:48:41 +00:00
|
|
|
const MAX_FRAMES = 25;
|
2019-08-15 13:11:30 +00:00
|
|
|
const MAX_LOOPS = 5;
|
2019-06-19 15:26:00 +00:00
|
|
|
|
2019-07-08 18:48:12 +00:00
|
|
|
// Get total number of frames of the animation from the hash.
|
|
|
|
const hash = window.location.hash;
|
|
|
|
const totalFrames = hash.slice(1);
|
|
|
|
console.log("Lottie has " + totalFrames + "total frames");
|
2019-06-27 23:22:42 +00:00
|
|
|
|
2019-07-08 18:48:12 +00:00
|
|
|
// Load the animation with autoplay false. We will control which
|
|
|
|
// frame to seek to and then will measure performance.
|
|
|
|
let anim = lottie.loadAnimation({
|
2019-06-19 15:26:00 +00:00
|
|
|
container: document.querySelector('.anim'),
|
|
|
|
renderer: RENDERER,
|
|
|
|
loop: false,
|
2019-07-08 18:48:12 +00:00
|
|
|
autoplay: false,
|
2019-06-19 15:26:00 +00:00
|
|
|
path: PATH,
|
|
|
|
rendererSettings: {
|
|
|
|
preserveAspectRatio:'xMidYMid meet'
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-07-11 17:48:41 +00:00
|
|
|
const t_rate = 1.0 / (MAX_FRAMES - 1);
|
2019-07-08 18:48:12 +00:00
|
|
|
let frame = 0;
|
2019-07-11 17:48:41 +00:00
|
|
|
let loop = 0;
|
2019-07-08 18:48:12 +00:00
|
|
|
const drawFrame = () => {
|
2019-07-11 17:48:41 +00:00
|
|
|
if (frame >= MAX_FRAMES) {
|
|
|
|
// Reached the end of one loop.
|
|
|
|
loop++;
|
|
|
|
if (loop == MAX_LOOPS) {
|
|
|
|
// These are global variables to talk with puppeteer.
|
|
|
|
window._lottieWebDone = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Reset frame to restart the loop.
|
|
|
|
frame = 0;
|
2019-07-08 18:48:12 +00:00
|
|
|
}
|
2019-06-27 23:22:42 +00:00
|
|
|
|
2019-07-08 18:48:12 +00:00
|
|
|
let t1 = Math.max(Math.min(t_rate * frame, 1.0), 0.0);
|
|
|
|
let seekToFrame = totalFrames * t1;
|
|
|
|
if (seekToFrame >= totalFrames-1) {
|
|
|
|
// bodymovin player sometimes draws blank when requesting
|
|
|
|
// to draw the very last frame. Subtracting a small value
|
|
|
|
// seems to fix this and make it draw the last frame.
|
|
|
|
seekToFrame -= .001;
|
|
|
|
}
|
2019-06-24 18:53:55 +00:00
|
|
|
|
2019-07-08 18:48:12 +00:00
|
|
|
anim.goToAndStop(seekToFrame, true /* isFrame */);
|
2019-07-11 17:48:41 +00:00
|
|
|
console.log("Used seek: " + (seekToFrame/totalFrames));
|
2019-07-08 18:48:12 +00:00
|
|
|
frame++;
|
2019-06-19 15:26:00 +00:00
|
|
|
window.requestAnimationFrame(drawFrame);
|
2019-07-08 18:48:12 +00:00
|
|
|
};
|
|
|
|
window.requestAnimationFrame(drawFrame);
|
2019-06-19 15:26:00 +00:00
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|