Last active
April 3, 2023 21:51
-
-
Save bobbiejwilson/1e51629090a33053932013eab0328683 to your computer and use it in GitHub Desktop.
Webflow Lottie Animations Access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var lottie, animations | |
// Return a promise that resolves to true once animation is loaded | |
async function animationLoaded(animation) { | |
if(animation.isLoaded) { | |
return true | |
} | |
return new Promise((resolve, reject) => { | |
animation.addEventListener('DOMLoaded', () => { | |
resolve(true) | |
}) | |
}) | |
} | |
// Return a promise that resolves to true once all animations are loaded | |
async function waitForAnimationsLoaded(animations) { | |
await Promise.all(animations.map(animationLoaded)) | |
} | |
async function initAnimations() { | |
lottie = Webflow.require('lottie').lottie | |
animations = lottie.getRegisteredAnimations() | |
await waitForAnimationsLoaded(animations) | |
} | |
var Webflow = Webflow || [] | |
Webflow.push(() => { | |
initAnimations() | |
.then(() => { | |
console.log('Initialized animations') | |
// hide splash screen | |
}) | |
.catch((error) => { | |
console.error(error) | |
}) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment