Files
fizzy/app/javascript/controllers/animation_controller.js
T
2024-11-01 09:32:12 -05:00

25 lines
535 B
JavaScript

import { Controller } from "@hotwired/stimulus"
import { nextFrame } from "helpers/timing_helpers"
export default class extends Controller {
static classes = [ "play" ]
static values = { playOnLoad: { type: Boolean, default: false } }
connect() {
if (this.playOnLoadValue) {
this.play()
}
}
async play() {
await nextFrame()
this.element.classList.remove(this.playClass)
this.#forceReflow()
this.element.classList.add(this.playClass)
}
#forceReflow() {
this.element.offsetWidth
}
}