Skip to content

ginpei/vue-routing-animation-demo

Repository files navigation

Vue Routing Animation Demo

Demo to animate something when you move pages using Vue.js.

Demo video. When you move to another page, some blocks fade in and pop up.

Live demo:

Inspired by a demo of ReactTransitionGroup:

Animating

Animation itself is implemented in short CSS in routing-animation.css:

[routing-animation] {
  visibility: hidden;
}

[routing-animation].is-preparedRoutingAnimation {
  animation: routingAnimation-show 300ms;
  visibility: visible;
}

@keyframes routingAnimation-show {
  0%   { opacity: 0; transform: translateY(1rem); }
  100% { opacity: 1; transform: translateY(0); }
}

The elements which have the attribute routing-animation are the target.

The class is-preparedRoutingAnimation is driven by BaseLayout.vue which is a wrapper component for all pages. It adds the class when routing so that they animate.

mounted() {
  const els = Array.from(this.$el.querySelectorAll('[routing-animation]'));
  els.forEach((el, index)=>{
    setTimeout(()=>el.classList.add('is-preparedRoutingAnimation'), 50 * index);
  });
},

Here is an example of usage of BaseLayout and routing-animation from Home.vue:

<template>
  <base-layout>
    <h1 routing-animation>Home</h1>
    <ul>
      <li routing-animation><router-link to="/notes/">Notes</router-link></li>
      <li routing-animation><router-link to="/about">About</router-link></li>
    </ul>
  </base-layout>
</template>

About

Demo to animate something when you move pages using vue.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages