Webflow + Lotties

Controlling Lotties w/ Javascript

No items found.
Overview
Controlling Lotties w/ Javascript
002
Lottie Tools & Alternatives
003
Circular Progress Bar
Circular Progress Bar w/ Lotties
5:33
102
Lottie + Interactions
8:44
102
Lottie + JavaScript
5:42
103
JavaScript-only
3:57
104
Choosing a Lottie
7:47
106
No items found.

Yes, you can control Webflow-loaded Lotties with Javascript.

Yes, it's a pain in the butt.

There are a few barriers you'll likely encounter, but all of them can be conquered.

Getting a handle on your Lottie

Since there may be several Lotties loaded in the page, it's important to be able to locate the right ones to control.

Method #1

const lottie = Webflow.require('lottie').lottie;

const animations = lottie.getRegisteredAnimations();

Then iterate through animations.lottie to find the right one.

animations.lottie[n].wrapper is the containing element, so if you've applied an id or custom attribute, you can identify that here.

Method #2 ( not currently working )

Set a custom attribute on the Lottie element of data-name = x

You should then be able to identify it through the Lottie library, e.g.

lottie.stop('x');

Reference

Controlling your Lottie

By default, Lotties want to auto-play, and there does not appear to be any setting in the designer to stop that.

Method #1 - Interaction Hack

However, you can hack this by adding an interaction to the lottie.

I use an element interaction with a click trigger, and I set the action to play lottie on the second click only. This prevents the autoplay with minimal interference to the page.

Since it's an element interaction, it can be carried with the element in components and cross-site copy-paste.

Other Possible Methods

These don't seem to work currently;

Stop the animation using script right on page load

isPaused = true and stop() don't appear to take effect. Both are ignored until the first full autoplay completes

Add a custom attribute ( tested, didn't work ).

data-lottie-percent = 0

Reference

References

Control Lottie via Javascript?

https://discourse.webflow.com/t/control-lottie-via-javascript/182219

var Webflow = Webflow || [];Webflow.push(function () {  // DOMready has fired  // May now use jQuery and Webflow api});


var Webflow = Webflow || [];
Webflow.push(function () {
  // DOMready has fired
  // May now use jQuery and Webflow api
});

Webflow.js and jQuery plugins

https://discourse.webflow.com/t/webflow-js-and-jquery-plugins/907

https://github.com/airbnb/lottie-web#lottie-has-several-global-methods-that-will-affect-all-animations

Table of Contents
Did we just make your life better?
Passion drives our long hours and late nights supporting the Webflow community. Click the button to show your love.