-
-
Save qawemlilo/e63630f2eb88d78fe82d3064942575bb to your computer and use it in GitHub Desktop.
Vue component for simple fade-out-in with Velocity.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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