Lottie-web: Hover effect. SVG + Animation?

Created on 28 Jul 2017  路  4Comments  路  Source: airbnb/lottie-web

Hi there!
I try to do a hover effect directly with an animation from ae. I don麓t know why, but it doesn麓t work... (That what I have written). Could you help me?

`var animation = bodymovin.loadAnimation({

container: document.getElementById("logo").addEventListener("mouseover", function(){ anim.play(); }),
renderer: "svg",
loop: true,
autoplay: false,
prerender: true,
path: "json/logo.json"

})`

Could I a svg image (logo) in the html embed and render the animation (json data) as hover?

Thank you! :)

Most helpful comment

Hey! It麓s alive, thank you so much!
That麓s what I wrote (maybe can it help someone ;)):

`var logo = document.getElementById("logo");
var animation = bodymovin.loadAnimation({
container: logo,
renderer: "svg",
loop: true,
autoplay: false,
prerender: true,
path: "json/logo.json"
});

logo.addEventListener("mouseenter", function () {
animation.play();
});

logo.addEventListener("mouseleave", function () {
animation.stop();
});`

All 4 comments

your animation instance is called "animation", have you tried doing animation.play() instead of anim.play() ?

Yes I did it, but with the same result... Maybe is it an animation麓s problem?

Does putting these separate work:

var logo = document.getElementById("logo");
var animation = bodymovin.loadAnimation({
container: logo,
renderer: "svg",
loop: true,
autoplay: false,
prerender: true,
path: "json/logo.json"
});
anim.addEventListener('DOMLoaded', function(){
logo.addEventListener("mouseover", function(){ anim.play(); });
}

Hey! It麓s alive, thank you so much!
That麓s what I wrote (maybe can it help someone ;)):

`var logo = document.getElementById("logo");
var animation = bodymovin.loadAnimation({
container: logo,
renderer: "svg",
loop: true,
autoplay: false,
prerender: true,
path: "json/logo.json"
});

logo.addEventListener("mouseenter", function () {
animation.play();
});

logo.addEventListener("mouseleave", function () {
animation.stop();
});`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RenanSgorlom picture RenanSgorlom  路  3Comments

zhengs picture zhengs  路  3Comments

processprocess picture processprocess  路  3Comments

phileastv picture phileastv  路  3Comments

dulllud picture dulllud  路  3Comments