javascript - 我如何使用 javascript 来实现这样用户只能在 Lottie 动画完全播放后触发悬停事件?

标签 javascript animation hover mouseevent lottie

我怎样才能做到这一点,以便用户只能在 Lottie 动画最初完整播放后触发鼠标悬停和鼠标左键事件。

目前,用户能够在动画播放过程中引发悬停事件,这是我不希望发生的事情。

谢谢

var anim4;
    var anim5 = document.getElementById('lottie5')
    var animation5 = {
        container: anim5,
        renderer: 'svg',
        loop: true,
        autoplay: false,   /*MAKE SURE THIS IS FALSE*/
        rendererSettings: {
        progressiveLoad: false},
        path: 'https://assets1.lottiefiles.com/packages/lf20_H2PpYV.json',
        name: 'myAnimation',
    };
    anim4 = lottie.loadAnimation(animation5);


    // SCROLLING DOWN
    var waypoint5 = new Waypoint({
     element: document.getElementById('lottie5'),
     handler: function(direction) {
       if (direction === 'down') {
         anim4.playSegments([[130,447],[358,447]], true);
         this.destroy()
       }
     },
       offset: '50%'
    })

    anim5.addEventListener("mouseenter", myScript1);
    anim5.addEventListener("mouseleave", myScript2);

function myScript1(){
    anim4.goToAndStop(500, true);
}

function myScript2(){
    anim4.playSegments([358,447],true);
}; 

最佳答案

    var anim4;
    var anim5 = document.getElementById('lottie5')
    var animation5 = {
        container: anim5,
        renderer: 'svg',
        loop: false,
        autoplay: true,   /*MAKE SURE THIS IS FALSE*/
        rendererSettings: {
        progressiveLoad: false},
        path: 'https://assets1.lottiefiles.com/packages/lf20_H2PpYV.json',
        name: 'myAnimation',
    };
    anim4 = lottie.loadAnimation(animation5);


    // SCROLLING DOWN
    var waypoint5 = new Waypoint({
     element: document.getElementById('lottie5'),
     handler: function(direction) {
       if (direction === 'down') {
         anim4.playSegments([[130,447],[358,447]], true);
         this.destroy()
       }
     },
       offset: '50%'
    })

    anim4.addEventListener("complete", function(){
        console.log('Animation completed!!');
        anim5.addEventListener("mouseenter", myScript1);
        anim5.addEventListener("mouseleave", myScript2);
    });

function myScript1(){
    anim4.goToAndStop(500, true);
}

function myScript2(){
    anim4.playSegments([358,447],true);
}; 

关于javascript - 我如何使用 javascript 来实现这样用户只能在 Lottie 动画完全播放后触发悬停事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59936546/

相关文章:

php - 检查站点的首次访问

javascript - 在 AJAX/JavaScript 中,如何引用 undefined variable (匿名函数)?

html - 围绕多个轴旋转 svg 元素

javascript - 如何添加:hover rule in js function?

jquery - 通过缩略图悬停进行图像交换?

javascript - 套接字.io : Receiving data from server node js

javascript - 在 Express 中运行自定义模块

swift - 线性 CABasicAnimation 在容器 View 中不是线性执行的

jquery - 如何为动画汉堡包图标使用 Font Awesome Bars

jquery - Jquery 悬停时淡入和淡出图像