requestAnimationFrame: what exactly is the timestamp?

后端 未结 3 1487
伪装坚强ぢ
伪装坚强ぢ 2021-02-20 11:15

I have always thought that timestamp used by requestAnimationFrame is the same as usual timestamp in JavaScript, that is number of milliseconds since January 1st, 1970. Today I

3条回答
  •  清酒与你
    2021-02-20 11:46

    It's a DOMHighResTimeStamp or a high-resolution timestamp (the same you get with window.performance.now()).

    The time stamp is:

    current time for when requestAnimationFrame starts to fire callbacks.

    The main difference between an ordinary timestamp and high-res timestamp is:

    DOMTimeStamp only has millisecond precision, but DOMHighResTimeStamp has a minimal precision of ten microseconds.

    Note: some browsers do not implement this aspect of rAF yet and may give you faulty or no value as argument.

    Some resources:

    • requestAnimationFrame
    • DOMHighResTimeStamp

提交回复
热议问题