How do I rewrite this animation with - requestAnimationFrame?

  • 0
    Made a little animation with setInterval
    How can you do it using requestAnimationFrame? Tried different options, but either gives an error or the animation doesn't start
    Code - sandbox
    JavaScript Cora Hutchinson, Mar 5, 2020

  • 1 Answers
  • 0
    const popupAnimate = () => {
    let startAnimate = performance.now();
    const loop = (now) => {
    let timePassed = now - startAnimate;
    popupContent.style.top = timePassed / 7 + "px";
    if (timePassed > 3000) return;

    requestAnimationFrame(loop);
    };
    requestAnimationFrame(loop);
    };
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!