2

How I can pass argument to reqestAnimationFrame ? let's say I have this code,how I can pass argument to requestAnimationFrame

var element = document.getElementById("SomeElementIWantToAnimate");
element.style.position = 'absolute';

function step(number) {
element.style.left = ""+Math.min(progress/10, 200) + "px";
window.requestAnimationFrame(step);
}

window.requestAnimationFrame(step); //how I can pass a "number" argument here
Matija
  • 493
  • 4
  • 9
  • 21

1 Answers1

0

The parameter is current timestamp, not a step and you need to call requestAnimationFrame again and again until your animation is done

I find this solution while I develop a small library I have created one, which is very simple and small

https://github.com/allenhwkim/jsanimation

Usage

import {slideInRight} from 'jsanimation';
slideInRight(el);
allenhwkim
  • 27,270
  • 18
  • 89
  • 122