juliangarnier / anime

JavaScript animation engine
https://animejs.com
MIT License
50.4k stars 3.68k forks source link

Why a cant use play/pause buttons? #876

Closed TreeFall1 closed 10 months ago

TreeFall1 commented 10 months ago

JS:

let elements = document.querySelectorAll(".el");
    let playBtn= document.querySelector('.play');
    let pauseBtn= document.querySelector('.pause');
    const circle = anime({
        targets: elements,
        left: "240px",
        borderRadius: ["0%", "50%"],
        duration: 1000,
        easing: 'easeInOutQuad',
        autoplay: false,
        // loop: true,
    });
playBtn.onclick = animation.play;
pauseBtn.onclick = animation.pause;

HTML:

Why my play/pause buttons doesnt work? Its says: Uncaught ReferenceError: animation is not defined

juliangarnier commented 10 months ago

It's because the animation variable is never declared, your animation variable is circle. Do this instead:

playBtn.onclick = circle.play;
pauseBtn.onclick = circle.pause;