Search code examples
javascripthtmllottie

How to show page after animation complete with Lottie and Javascript


Im quite a beginner, experimenting with SVG animations. I have made a animation and loaded it in my simple html page with Lottie. But I been trying to make it destroy itself and show the rest of the page content, which is the header and p.

I seen this code, googling this, but not sure where to put it, went for what I thought was logical, and paste it right under. But did not get what I wanted.

ani.addEventListener('complete', function(){ ani.destroy() })

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial- 
    scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="master.css">
    <script src="master.js"></script>    
    <script src="lottie.js"></script>
    <title>Document</title>
</head>
<body onload="start()">

    <div id="velkommen"></div>

    <header>
        <h1>Min header</h1>
    </header>

    <p>tekstteksttekstketkekte</p>


</body>
</html>


window.onload(start())

function start(){
    var container = document.getElementById("velkommen");
    var animation = bodymovin.loadAnimation({    
        container: container, 
        renderer: 'svg',
        loop: false,
        autoplay: true,
        path: 'data.json'
     });
}

Solution

  • I found out! Incase someone else was wondering :

    function start(){
        var anim;
    var animdata ={
        container: document.getElementById("velkommen"),
        renderer: "svg",
        loop: false,
        autoplay: true,
        path: "data.json"
    };
    anim = bodymovin.loadAnimation(animdata);
    anim.addEventListener('complete',stopa);
    }
    
    function stopa(){
        document.getElementById("velkommen").style.display = "none";
    }