2

Vue has the v-if and v-for directives which create/remove the element in the DOM depending on the condition. To animate v-if and v-for, you have to use the Transition and TransitionGroup built-in components respectively. How can I use animate.css's built-in animations with these Vue built-in components?

Example;

<script setup lang="ts">
import { ref } from "vue";

const isModalVisible = ref<boolean>(false);
</script>
<button @click="() => (isModalVisible = true)">Click Me<button>

<Transition name="I want an animate.css animation here">
    <Modal v-if="isModalVisible" />
</Transition>
1
  • Have a look at the think VueUse/Motion If you don't find any good solution to use animate.css you can use VueUse/Motion Commented Jan 23, 2023 at 10:15

1 Answer 1

2

The <Transition> component accepts props to override which class to apply, instead of generate ones from the given name. (See documentation)

<Transition
  enterActiveClass="animate__animated animate__bounce"
>
  <Modal v-if="isModalVisible" />
</Transition>

Example in playground

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.