我使用requestAnimationFrame(animate);
函数改变文本颜色:
requestAnimationFrame(animate);
function animate(time){
... // change text color here
if (offset_s < offset_e) {requestAnimationFrame(animate);}
}
offset_s
和offset_e
表示文本颜色变化的起始和结束位置。在某些情况下,动画应持续2秒钟,但在其他情况下则为5秒钟,但是这两种情况下offset_e - offset_s
可能相同。我该如何根据给定的时间(以秒/毫秒为单位)控制动画速度?