Last active
July 19, 2021 10:18
-
-
Save Fanna1119/683c2b7406d22d5e4e64801a0ca9637d to your computer and use it in GitHub Desktop.
vue router animations
This file contains hidden or 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
import { animate } from "@okikio/animate"; | |
// import anime from 'animejs/lib/anime.es.js'; | |
//transitions using animate | |
//animates end event is `onfinish` | |
function fadeIn(el, done) { | |
animate({ | |
targets: el, | |
opacity: [0, 1], | |
easing: 'easeInOutSine', | |
onfinish: done | |
}) | |
} | |
function fadeOut(el, done) { | |
animate({ | |
targets: el, | |
opacity: [1, 0], | |
easing: 'easeInOutSine', | |
onfinish: done | |
}) | |
} | |
//end | |
//transitions using animejs | |
//animejs end event is `complete` | |
function useFadeIn(el, done) { | |
console.log(el) | |
anime({ | |
targets: el, | |
opacity: [0, 1], | |
easing: 'easeInOutSine', | |
complete: done, | |
}) | |
} | |
function useFadeOut(el, done) { | |
anime({ | |
targets: el, | |
opacity: [1, 0], | |
easing: 'easeInOutSine', | |
complete: done, | |
}) | |
} | |
export { | |
fadeIn, fadeOut, | |
// useFadeOut, useFadeIn | |
} |
This file contains hidden or 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> | |
<div> | |
<nav-bar /> | |
<router-view v-slot="{ Component }"> | |
<transition @enter="fadeIn" @leave="fadeOut" v-bind:css="false" mode="out-in"> | |
<component :is="Component" /> | |
</transition> | |
</router-view> | |
</div> | |
</template> | |
<script> | |
import navigation from '@components/navigation.vue' | |
import { fadeIn, fadeOut } from './animations.js' | |
export default { | |
components: { | |
"nav-bar": navigation, | |
}, | |
setup() { | |
return { | |
fadeIn, fadeOut, | |
} | |
} | |
} | |
</script> | |
<style> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment