Skip to content

Instantly share code, notes, and snippets.

@bobbiejwilson
Last active April 3, 2023 21:51
Show Gist options
  • Save bobbiejwilson/1e51629090a33053932013eab0328683 to your computer and use it in GitHub Desktop.
Save bobbiejwilson/1e51629090a33053932013eab0328683 to your computer and use it in GitHub Desktop.
Webflow Lottie Animations Access
<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