Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fading out removal of element from DOM with Stimulus

I currently have this simple stimulus JS controller which removes an element from DOM

import { Controller } from "stimulus"
export default class extends Controller {
  static targets = [ "element" ]
    close () {
        this.elementTarget.remove()
    }
}

Is there a way to fade out the element before removal?

like image 269
vince Avatar asked Oct 26 '25 18:10

vince


1 Answers

I got something to kind of work with tailwind. I'll keep this till I find a more general solution

import { Controller } from "stimulus"
export default class extends Controller {
  static targets = [ "element" ]
    close () {
        this.element.classList.add('transform', 'opacity-0', 'transition', 'duration-1000');
        setTimeout(() => this.elementTarget.remove(), 1000)
    }
}
like image 74
vince Avatar answered Oct 29 '25 08:10

vince