我希望将鼠标悬停事件添加到从After Effects导出的SVG中。我希望SVG在mouseover上播放。到目前为止,我已经使用了animation-play-state属性,但是它没有起作用。我还尝试在脚本中使用onmouseover并尝试为mouseover添加事件侦听器,但仍然没有。我究竟做错了什么?

var params = {
    container: document.getElementById('bodymovin'),
    renderer: 'svg',
    loop: true,
    autoplay: true,
    animationData: animationData

};

var anim;

anim = bodymovin.loadAnimation(params);

最佳答案

我这样做是对我有用:

animContainer = document.getElementById('bodymovin');

var params = {
    container: animContainer,
    renderer: 'svg',
    loop: true,
    autoplay: true,
    autoplay:false,
    autoloadSegments: false,
    path: 'data.json'// path to your data.json file you rendered from AE

};

var anim;

anim = bodymovin.loadAnimation(params);
animContainer.addEventListener("mouseover", myScript);

function myScript(){
    anim.play();
}

10-04 16:33