A simple set of directives to perform transition animations in components and HTML elements.
npm install vue-simple-transitions
You can import the package in two ways:
// main.ts or main.js
import { createApp } from 'vue'
import vueSimpleTransitions from 'vue-simple-transitions'
import 'vue-simple-transitions/styles.css'
const app = createApp(App)
app.use(vueSimpleTransitions)
app.mount('#app')
// main.ts or main.js
import { createApp } from 'vue'
import { vAnim, vAnimDelay, vAnimDuration } from 'vue-simple-transitions'
import 'vue-simple-transitions/styles.css'
const app = createApp(App)
app.directive('anim', vAnim)
app.directive('anim-delay', vAnimDelay)
app.directive('anim-duration', vAnimDuration)
app.mount('#app')
Add the transitions controller to App.vue.
After that vAnimController will observe any instance of the directives in any element or component of your project.
<template>
<h1 v-anim v-anim-delay="200">
Hello world
</h1>
<your-component
v-anim="'slide-x-left'"
v-anim-delay="400"
v-anim-duration="1200"
/>
</template>
<script setup lang="ts">
import { onMounted } from 'vue'
import { vAnimController } from 'vue-simple-transitions'
onMounted(() => {
vAnimController()
})
</script>
Directive | Value Type | Default | Details |
---|---|---|---|
v-anim | string |
fade-in |
Sets the base transition class to the element/component. It also sets the name of the transition that we want to trigger. |
v-anim-delay | number |
500 |
Sets the transition-delay to the element/component. |
v-anim-duration | number |
500 |
Sets the transition-duration to the element/component. |
By default vue-simple-transitions includes these transitions:
fade-in
fade-out
slide-x-left
slide-x-right
slide-y-bottom
slide-y-top
Custom transitions can be added in CSS under this format:
/* Base state */
.--anim.[NAME-OF-YOUR-CLASS] { ... }
/* .--anim.my-custom-transition { ... } */
/* Animated state */
.--anim.[NAME-OF-YOUR-CLASS].--animated { ... }
/* .--anim.my-custom-transition.--animated { ... } */