Nowadays, we can do it with just a few lines of pure CSS, without a single line of JS. The snippet below uses a few modern Web featues: popover element, CSS nesting, transitioninig properties with discrete animation behaviour and @starting-style.
It's packed with many goodies for such a tiny snippet, isn't it?
Everything I presented here I learned from 'Using @starting-style and transition-behavior for enter and exit stage effects' by Adam Argyle and 'Four new CSS features for smooth entry and exit animations' by Una Kravets and Joey Arhar.
Collection
[
|
...
]