vue 翻牌子动画_VUE单页面切换动画(全网最好的切换效果)

本文介绍了一种在Vue应用中实现翻牌子动画的视图切换方法。通过监听路由变化,动态设置视图过渡动画,利用CSS3关键帧动画实现左右滑动效果。同时,结合Vuex管理状态,根据前进或后退方向调整动画方向。
摘要由CSDN通过智能技术生成

// 视图切换动画逻辑

let history = window.sessionStorage

let historyCount = history.getItem('count') * 1 || 0

function routerTransition (to, from) {

const toIndex = history.getItem(to.name)

const fromIndex = history.getItem(from.name)

let direction = 'forward'

if (toIndex) {

if (toIndex >= fromIndex || !fromIndex) {

store.commit('UPDATE_DIRECTION', {direction})

} else {

direction = 'reverse'

store.commit('UPDATE_DIRECTION', {direction})

}

} else {

++historyCount

history.setItem('count', historyCount)

to.path !== '/' && history.setItem(to.name, historyCount)

direction = 'forward'

store.commit('UPDATE_DIRECTION', {direction})

}

}

router.beforeEach(function (to, from, next) {

routerTransition(to, from)

next()

})

import '@/assets/iconfont/iconfont.css'

import { Loading, TransferDom } from 'vux'

import {mapState} from 'vuex'

import noNetwork from '@/page/system/callback/noNetwork.vue'

export default {

directives: {

TransferDom

},

computed: {

...mapState({

isLoading: state => state.isLoading,

direction: state => state.direction,

isNetworkOnline: state => state.isNetworkOnline

})

},

// dynamically set transition based on route change

watch: {

'$route' (to, from) {

if (this.direction === 'forward') {

this.viewAnimate = 'slide-left'

} else {

this.viewAnimate = 'slide-right'

}

}

},

data () {

return {

viewAnimate: 'slide-left'

}

},

components: {

Loading,

noNetwork

}

}

@import '~vux/src/styles/reset.less';

@import '~vux/src/styles/close.less';

@import '~@/styles/common.less';

body {

background-color: #fbf9fe;

}

@keyframes slideInLeft {

from {

transform: translate3d(100%, 0, 0);

opacity: 1;

}

to {

transform: translate3d(0, 0, 0);

opacity: 1;

}

}

@keyframes slideInRight {

from {

transform: translate3d(-100%, 0, 0);

opacity: 1;

}

to {

transform: translate3d(0, 0, 0);

opacity: 1;

}

}

@keyframes slideLeftOut {

from {

transform: translate3d(0, 0, 0);

opacity: 0;

}

to {

transform: translate3d(100%, 0, 0);

opacity: 0;

}

}

@keyframes slideRightOut {

from {

transform: translate3d(0, 0, 0);

opacity: 0;

}

to {

transform: translate3d(-100%, 0, 0);

opacity: 0;

}

}

.slide-left-enter-active {

animation: slideInLeft .3s forwards;

z-index:5;

}

.slide-left-leave-active {

animation: slideLeftOut .3s forwards;

z-index:3;

}

.slide-right-enter-active {

animation: slideInRight .3s forwards;

z-index:5;

}

.slide-right-leave-active {

animation: slideRightOut .3s forwards;

z-index:3;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值