将参数传递给requestAnimationFrame [duplicate]

问题描述 投票:2回答:1

这个问题在这里已有答案:

我如何将参数传递给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
javascript requestanimationframe
1个回答
0
投票

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

当我开发一个我创建的小库时,我找到了这个解决方案,它非常简单和小巧

https://github.com/allenhwkim/jsanimation

用法

import {slideInRight} from 'jsanimation';
slideInRight(el);
© www.soinside.com 2019 - 2024. All rights reserved.