Skip to content

Instantly share code, notes, and snippets.

@cprass
Created October 9, 2016 09:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cprass/f43c87130d4e76db543c71addd23deb0 to your computer and use it in GitHub Desktop.
Save cprass/f43c87130d4e76db543c71addd23deb0 to your computer and use it in GitHub Desktop.
Vue component for simple fade-out-in with Velocity.js
<template>
<transition
name="fade"
mode="out-in"
v-on:before-enter="beforeEnter"
v-on:enter="enter"
v-on:before-leave="beforeLeave"
v-on:leave="leave"
>
<slot></slot>
</transition>
</template>
<script>
import Velocity from 'velocity-animate'
export default {
props: {
duration: {
default: false
}
},
methods: {
beforeEnter (el) {
el.style.opacity = 0
},
enter (el, done) {
var vm = this
Velocity(el,
{ opacity: 1 },
{
duration: vm.duration ? vm.duration : 500,
easing: [ 0.39, 0.67, 0.04, 0.98 ],
complete: function () {
done()
}
}
)
},
beforeLeave (el) {
el.style.opacity = 1
},
leave (el, done) {
var vm = this
Velocity(el,
{ opacity: 0 },
{
duration: vm.duration ? vm.duration : 500,
easing: [ 0.39, 0.67, 0.04, 0.98 ],
complete: function () {
done()
}
}
)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment