vue移动端过渡动画_Vue.js实现微信过渡动画左右切换效果

前言

在awesomes上寻找移动端框架的时候意外发现了vux的页面切换效果,后面由于其他考虑没有选用vuex但是这个切换效果确实感觉很有新意,也就看了下源码,这里贴一份备用。

需要用到的技术栈:Vue+Vuex

先看看效果图

ee17e096ca46804586b1765381aa911b.gif

过渡动画

示例代码

//app.vue

import { mapState } from 'vuex'

import sideFooter from "./components/Footer.vue"

export default {

name: 'app',

data () {

return {

showFooter : false

}

},

components : {

sideFooter

},

computed:{

...mapState({

direction: state => state.mutations.direction

})

},

}

.vux-pop-out-enter-active,

.vux-pop-out-leave-active,

.vux-pop-in-enter-active,

.vux-pop-in-leave-active {

will-change: transform;

transition: all 250ms;

height: 100%;

top: 0;

position: absolute;

backface-visibility: hidden;

perspective: 1000;

}

.vux-pop-out-enter {

opacity: 0;

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

}

.vux-pop-out-leave-active {

opacity: 0;

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

}

.vux-pop-in-enter {

opacity: 0;

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

}

.vux-pop-in-leave-active {

opacity: 0;

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

}

// main.js

const history = window.sessionStorage;

history.clear()

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

history.setItem('/', 0);

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

const toIndex = history.getItem(to.path);

const fromIndex = history.getItem(from.path);

if (toIndex) {

if (!fromIndex || parseInt(toIndex, 10) > parseInt(fromIndex, 10) || (toIndex === '0' && fromIndex === '0')) {

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

} else {

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

}

} else {

++historyCount;

history.setItem('count', historyCount);

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

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

}

next()

});

这里还用到了vuex,但是我stroe写了很多就不提出来了,主要就是通过 UPDATE_DIRECTION方法更新每一次的路由方向是前进还是后退。

man.js里面主要思想就是给路由增加一个索引存到sessionStorage里面,以点击过的索引值不变,新增加的路由,索引增加1,同时count+1,这样在页面切换时通过比较索引值的大小,大的向右小的向左,做到左右有规律的过渡。

好了至此一个左右切换的过渡效果就成了,最近由于一直在开发也没怎么更新文章,如果有朋友有好的想法欢迎与我交流。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值