D
D
Dima2018-04-15 16:07:24
Vue.js
Dima, 2018-04-15 16:07:24

Why is transition animation not working for 1 element in vue.js?

I did everything according to this documentation, the transition does not work :(
I also made the transition a separate element, it did not help either. What is the reason?
Here is the code and a link to the sandbox: https://codepen.io/qpz_here/pen/vRqVYY

<div id="app">
  <button v-on:click="show = !show">Анимация</button>
  <section v-if="show" transition="fade"></section>
</div>

section {
  width: 300px;
  height: 300px;
  background: #007aff;
}
button {
  padding: 20px 10px;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}

new Vue ({
  el: '#app',
  data: {
  show: true,
  }
})

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-04-15
@qpz

I did everything according to this documentation ...

<section v-if="show" transition="fade"></section>

Not all. The element being animated must be placed in a transition - it's a component, not an attribute at all. It will be correct like this:
<transition name="fade">
  <section v-if="show"></section>
</transition>

Or, if using the pug syntax:
transition(name="fade")
  section(v-if="show")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question