3.4 · Popovers & positioning

Animate from nothing: @starting-style

Animate elements in from display: none, and back out again.

Transitions only run when a value changes. An element that was just added, or just went from display: none to visible, has no previous value. @starting-style provides one, so the element can transition in from it.

Animating out is the other half. display and overlay are discrete properties that flip instantly. transition-behavior: allow-discrete (written here as the allow-discrete keyword) delays the flip until the fade has finished.

Before
el.hidden = false
requestAnimationFrame(() => {
  requestAnimationFrame(() => {
    el.classList.add('is-visible')
  })
})
// and a transitionend listener to hide
Now
[popover] {
  transition: opacity 0.4s,
    display 0.4s allow-discrete,
    overlay 0.4s allow-discrete;
  opacity: 0;

  &:popover-open {
    opacity: 1;
    @starting-style { opacity: 0; }
  }
}