Skip to content

Instantly share code, notes, and snippets.

@happyDemon
Last active March 5, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happyDemon/53fb988e8cc30720c0c294afe9aedc63 to your computer and use it in GitHub Desktop.
Save happyDemon/53fb988e8cc30720c0c294afe9aedc63 to your computer and use it in GitHub Desktop.
Vue.js explained through pokemon
export default {
animations: [
{
// call this transition with <transistion-attack>HTML TO TRANSITION</transition-attack>
tag: 'transition-attack',
// We don't want to trigger the transition on initial render
onAppear: false,
// Ignore CSS animations that happen to have the same name
css: false,
// Define the animation hooks
events: {
// Always start hidden
beforeEnter: function (el) {
el.style.opacity = 0
},
// Move the text up when it appears in .4s, then hide it in .2s
afterEnter: function (el) {
Velocity(el, {opacity: 1, translateY: '-40px'}, {duration: 400})
Velocity(el, {opacity: 0}, {duration: 200})
}
}
}
],
register(vue){
// Loop over the defined animations
this.animations.forEach((animation) => {
// Register each animation as a component
vue.component(animation.tag, {
functional: true,
// Render a transition tag, assign the animation methods
render(createElement, context){
// Assign element props and register events
const data = {
props: {
name: animation.tag,
mode: 'out-in',
appear: (typeof animation.onAppear == 'undefined') ? false : animation.onAppear,
css: (typeof animation.css == 'undefined') ? true : animation.css
},
on: animation.events
}
// Render the element
return createElement('transition', data, context.children)
}
})
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment