Lottie-web: how to make the final width equal to the exact width of the animation

Created on 10 Dec 2017  路  10Comments  路  Source: airbnb/lottie-web

for example
https://www.lottiefiles.com/61-octopus

the animation it self is 220 wide, while the svg is 800x600, this makes it very hard to reason about if we want to make the animation responsive to different screen sizes, specially if we have some text anywhere near the animation.

is there a way to achieve that through the api ? or maybe editing the json file directly ?

All 10 comments

It's complicated to change the composition's size because all property values are relative to the original size.
The easiest way I can think of is to change the viewBox and preserveAspectRatio values after the animation is loaded.

is there a formula to do that ? maybe a link to some guide that describe the process ?

atm a very hacky way would be resize the wrapper div with overflow hidden and scale the svg, but will fail big time if you have a text that needs to align with the animation.

I don't think there's a formula. It really depends on what you're looking for and the context of the animation.
I'd suggest that you try it to see if it fits your needs.

okay, np, maybe u can tell me how would u achieve that with the above example so i can use it as a guide ?

What are you trying to achieve in the above example? do you have a more precise case somewhere to check out?

this is the current with most of the examples on lottie, the animation is 800x600

1

this is the actually size of the animation which is what am trying to achieve instead of the above image

2

in the console set the svg parent's width to 220px;
and change the viewBox to "290 0 220 600"

perfect, last question

  • is there a way to change the viewBox through body movin ?

no, there is not at the moment

馃槥 , okay thanx for all your help, appreciated 馃弳

Was this page helpful?
0 / 5 - 0 ratings

Related issues

processprocess picture processprocess  路  3Comments

Ipaulsen picture Ipaulsen  路  4Comments

samiam2017 picture samiam2017  路  3Comments

yannieyeung picture yannieyeung  路  3Comments

deborabm picture deborabm  路  3Comments