Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically change Vue.js transition

I want to dynamically change what kind of animation happens depending on a user's action. So for example, when the first button is clicked and the leave animation is called the "hello" element should use the bounceOutRight animation. However, if the user clicks the second button the "hello" element should use the bounceOutLeft animation. This example comes from the vue.js documentation and I am trying to expand on it. As in the vue example it uses the animate.css library.

I tried using v-bind:leave-active-class="animated bounceOutRight" but that threw an error as an invalid expression.

<button @click="show = !show">
  Toggle Bounce Right
</button>
<button @click="show = !show">
  Toggle Bounce Left
</button>
<transition
  name="custom-classes-transition"
  enter-active-class="animated tada"
  leave-active-class="animated bounceOutRight"
>
  <p v-if="show">hello</p>
</transition>

like image 680
dpst Avatar asked Dec 18 '16 16:12

dpst


People also ask

Is Vue good for animation?

vue-kinesisIt's a powerful animation tool that can be used by developers to create superb animations. It also allows the use of various custom attributes to help achieve the desired effect.

What is Transition Group Vue?

<TransitionGroup> is a built-in component designed for animating the insertion, removal, and order change of elements or components that are rendered in a list.


1 Answers

You can use v-bind for this purpose, you can have name of transition as vue data variable and following will make sure it is dynamic:

<transition
  v-bind:name="className"
  v-bind:enter-active-class="enterClassName"
  v-bind:leave-active-class="leaveClassName"
>

or in short

<transition
  :name="className"
  :enter-active-class="enterClassName"
  :leave-active-class="leaveClassName"
>
like image 170
Saurabh Avatar answered Oct 08 '22 07:10

Saurabh