3

I have a modal which is a white container on top of a semi-transparent dark backdrop. When this modal is triggered I want the backdrop to fade in, and after that I want the white container to slide up from bottom of the screen.

But while the fade-in works, the slide up doesn't. What am I doing wrong?

Template:

<transition name="modal">
  <div v-if="showModal" class="backdrop">
    <transition name="content">
      <div v-if="showModal" @click="showModal = false" class="container">
        content
      </div>
    </transition>
  </div>
</transition>

CSS animation:

.modal-enter-active {
  animation: fade-in-and-slide-up 1s;
}

.content-enter-active {
  animation: wait-and-fade-in 4s;
}

@keyframes wait-and-fade-in {
  0% {
    opacity: 0;
  }

  66% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes fade-in-and-slide-up {
  0% {
    transform: translateY(100%);
  }

  50% {
  }

  100% {
    transform: translateY(0);
  }
}

Codesandbox

4

1 回答 1

2

To enable the transition on initial render, use appear:

<transition name="modal">
    <div v-if="showModal" class="backdrop">
      <transition name="content" appear>
                                   

demo

于 2021-04-03T22:36:31.507 回答