Hello,
I have added a Lottie animation to my Webflow page using the Webflow program and adding a lottie element. I want an action to occur when the animation finishes. Specifically, I want the animation to loop at different speeds. I have some javascript that works that changes the speed of the animation whenever I reload the page, so I know changing the speed of the animation through javascript is possible. I would like this action to occur when the animation finishes, rather than when the page loads.
I found some javascript code examples using the addEventListener, which looks like what I am looking for. I am using the addEventListener just to display the message āAnimation Finishedā to show that the animation has reached an end, but it doesnāt work.
Just for your info, ālottie_speedā is the id of the Lottie animation.
I am not good at javascript. Can someone point me in the right direction to come up with a solution? Thanks for any help! The script is below:
window.onload = function() {
// Below script gets a random number between 1 and 11. THIS WORKS
let speed = 20;
speed += (Math.random() - 0.5) * 1;
speed = Math.floor(Math.random() * 11) + 1
lottie_loaded_message.textContent=āmessageā;
const element = document.getElementById(ālottie_speedā);
const duration = element.dataset.duration;
//Sets a new random speed of lottie animation. THIS WORKS WHENEVER I RELOAD THE PAGE
lottie_speed.dataset.duration = speed;
//When animation is complete, displays message. THIS IS NOT WORKING.
element.addEventListener(ācompleteā, function() {
lottie_loaded_message.textContent=āanimation completeā;
console.log (āAnimation Finished!ā);
});
};
Here is my public share link: LINK
(how to access public share link)