blockless
Rich Harris 10 months ago
parent 3169490d7f
commit 15b47d2c55

@ -34,12 +34,11 @@ class Animation {
#keyframes; #keyframes;
#duration; #duration;
#target; #target;
#offset = 0;
#finished = () => {};
#cancelled = () => {};
/** @type {() => void} */ currentTime = 0;
#finished;
/** @type {() => void} */
#cancelled;
/** /**
* @param {HTMLElement} target * @param {HTMLElement} target
@ -50,10 +49,7 @@ class Animation {
this.#target = target; this.#target = target;
this.#keyframes = keyframes; this.#keyframes = keyframes;
this.#duration = options.duration || 0; this.#duration = options.duration || 0;
this.currentTime = 0; this.#offset = raf.time;
this.#finished = () => {};
this.#cancelled = () => {};
// Promise-like semantics, but call callbacks immediately on raf.tick // Promise-like semantics, but call callbacks immediately on raf.tick
this.finished = { this.finished = {
@ -80,7 +76,7 @@ class Animation {
} }
_update() { _update() {
this.currentTime = raf.time; this.currentTime = raf.time - this.#offset;
const target_frame = this.currentTime / this.#duration; const target_frame = this.currentTime / this.#duration;
this._applyKeyFrame(target_frame); this._applyKeyFrame(target_frame);

Loading…
Cancel
Save