将参数传递给requestAnimationFrame

时间:2016-11-18 23:32:16

标签: javascript requestanimationframe

如何将参数传递给reqestAnimationFrame? 假设我有这个代码,我如何将参数传递给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

1 个答案:

答案 0 :(得分:0)

该参数是当前时间戳,不是一步,您需要一次又一次调用requestAnimationFrame直到动画完成

我在开发一个小型图书馆时找到了这个解决方案 我创建了一个,它非常简单而且很小

https://github.com/allenhwkim/jsanimation

用法

import {slideInRight} from 'jsanimation';
slideInRight(el);
相关问题