Animate the lightbox

This commit is contained in:
Andy Smith
2025-07-30 17:26:05 -05:00
parent c00914b9c8
commit 3f7f414c34
3 changed files with 36 additions and 16 deletions
@@ -3,13 +3,25 @@ import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "image", "dialog", "zoomedImage" ]
connect() {
this.dialogTarget.addEventListener('transitionend', this.onTransitionEnd.bind(this))
}
// Only remove the image src after the CSS transition has finished
onTransitionEnd(event) {
if (this._waitingForTransition && !this.dialogTarget.open) {
this._waitingForTransition = false
this.zoomedImageTarget.src = ""
}
}
open(event) {
this.dialogTarget.showModal()
this.#set(event.target.closest("a"))
}
reset() {
this.zoomedImageTarget.src = ""
this._waitingForTransition = true
}
#set(target) {