Lottie-web: Possible to add class/id to svg elements?

Created on 11 Feb 2016  路  16Comments  路  Source: airbnb/lottie-web

To add some interactivity to the animation on the webpage, I would like to know if it is possible to add ID/classes to the svg elements to later add event listeners to them (after loading the animation) to control some parts of the animation with JS. Also, please let me know your advise on the best way/recommendation to add interactivity to the animations as I'm planning to use them for some UI elements.

Most helpful comment

@rezwanferdous name your layers starting with a "." or a "#" and they will get exported with the name as a class or an id respectively.

All 16 comments

Sorry to bug you, just found out this is a duplicate of #32

Thanks though! Great Library.

hello, can you tell me how you have added the class and id's? what the way of export to get id and class?

@rezwanferdous name your layers starting with a "." or a "#" and they will get exported with the name as a class or an id respectively.

should i export with glyph? sorry i'm actually still learning this tool. i just love using it. thank you so much

@rezwanferdous glyphs are only intended for text layers. If not, they have no effect on the export.

alright i got it. Thank you so much...it's so much. You have no idea how much i love this bodymovin.

@bodymovin Hi, I maybe have new possible use case for this. what I am trying to do is to clip element that is outside of the SVG generated by lottie. At the moment I cannot do that because lottie generates random ID for defs clipPath element.

@Panksi hi, I just uploaded a new version that sets incremental ids instead of random ones, as long as the animations don't change.
It can help for your use case.

Hi @bodymovin,

Can I add bodimovin to many elements based on element ids. So I can add hover and out animation on indiviual element. Otherwise it work with all element on a single.

Thanks

@trisghosh yes, you can load different animations on different dom elements on your page

@Panksi hi, I just uploaded a new version that sets incremental ids instead of random ones, as long as the animations don't change.
It can help for your use case.

Thanks dude, that's awesome.
somehow I missed the reply , but I have seen it just now. nevertheless, it will be useful in the future projects.

@bodymovin,

Dont you think that your answer is no where relvant to my question. I have used your Plugin many times and loaded diifferent animations too. For your help I am pasting my question again, with an huge expectation of correct answer from Author himself. Thanks in advance :

Can I add bodimovin to many elements based on element ids. So I can add hover and out animation on indiviual element. Otherwise it work with all element on a single.

@trisghosh can you rephrase your question or give more info of what you need?

Hey @bodymovin! Is this still possible? I have a json file exported and wanted to test quickly if names on layers are converted to IDs without success. I think having this is really cool, but kind of undocumented.

@fjcero Hi, yes this is still possible. Here is the documentation on how to use it.
https://github.com/airbnb/lottie-web/wiki/SVG-and-HTML-ids-and-classes-to-reference-via-css-or-select-via-Javascript
Let me know if it is not working for you.

@bodymovin Amazing! I didn鈥檛 checked the Wiki, not sure why I didn鈥檛 find it quickly. This is really cool, thanks for the link!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leantide picture leantide  路  3Comments

ochanje210 picture ochanje210  路  3Comments

cpdt picture cpdt  路  4Comments

DannyK123456 picture DannyK123456  路  3Comments

yannieyeung picture yannieyeung  路  3Comments