vue开发APP切换页面动画过度效果

实现问题

1.如何判断切换路由时是前进还是后退

2.每次切换时向左向右切换动画如何实现

实现原理

1.我们需要给各个页面定义层级,在切换路由时判断用户是进入哪一层页面,如果用户进入更高层级那么做前进动画,如果用户退到低层级那么做后退动画.

import VueRouter from 'vue-router'
import Home from '../components/home/home'
import User from '../components/user/user'

var router = new VueRouter({
    routes:[{
        name:'test',
        path:'/',
        meta:{index:0},//meta对象的index用来定义当前路由的层级,由小到大,由低到高
        component:{
            template:'
test
' } },{ name:'home', path:'/home', meta:{index:1}, component:Home },{ name:'user', path:'/user/:id', meta:{index:2}, component:User }] });

2.监控路由跳转,判断切换页面之间的层级关系,并以此来判断路由前进或者后退.





3.编写slide-left 和 slide-right 类的动画

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 500ms;
  position: absolute;
}
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}

你可能感兴趣的:(前端开发,全栈工程师,vue)