Vue.js实现微信过渡动画左右切换效果
作者:Yunfly 时间:2023-07-02 17:03:10
前言
在awesomes上寻找移动端框架的时候意外发现了vux的页面切换效果,后面由于其他考虑没有选用vuex但是这个切换效果确实感觉很有新意,也就看了下源码,这里贴一份备用。
需要用到的技术栈:Vue+Vuex
先看看效果图
过渡动画
示例代码
//app.vue
<transition :name="'vux-pop-' + (direction === 'forward' ? 'in' : 'out')">
<keep-alive>
<router-view class="router-view" ></router-view>
</keep-alive>
</transition>
<script>
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
})
},
}
</script>
<style scoped>
.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);
}
</style>
// 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,这样在页面切换时通过比较索引值的大小,大的向右小的向左,做到左右有规律的过渡。
好了至此一个左右切换的过渡效果就成了,最近由于一直在开发也没怎么更新文章,如果有朋友有好的想法欢迎与我交流。
来源:http://www.jianshu.com/p/a29d5ecfaadb
标签:vue,过渡动画,微信
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
关于Python去除字符串中空格的方法总结
2022-05-07 17:27:11
Python中matplotlib如何改变画图的字体
2023-02-19 16:46:38
![](https://img.aspxhome.com/file/2023/9/127589_0s.png)
Python3使用SMTP发送带附件邮件
2022-02-10 12:05:53
![](https://img.aspxhome.com/file/2023/8/63208_0s.jpg)
python实现简易数码时钟
2023-09-20 12:32:57
![](https://img.aspxhome.com/file/2023/9/127749_0s.png)
MySQL 有输入输出参数的存储过程实例
2024-01-24 23:00:01
Python变量赋值的秘密分享
2021-10-12 11:53:04
![](https://img.aspxhome.com/file/2023/9/98889_0s.png)
Python Pandas 对列/行进行选择,增加,删除操作
2022-10-29 03:55:52
Python多线程的使用详情
2023-05-29 15:13:36
pytorch中tensor张量数据类型的转化方式
2022-03-19 20:07:24
window10下mysql 8.0.20 安装配置方法图文教程
2024-01-14 19:08:59
![](https://img.aspxhome.com/file/2023/0/121280_0s.jpg)
使用python远程操作linux过程解析
2021-12-01 21:05:27
优化SQLServer数据库服务器内存配置的策略
2009-05-13 10:25:00
打包python 加icon 去掉cmd黑窗口方法
2021-12-01 15:26:38
PHP使用laravel邮件服务发送邮件
2023-05-25 03:48:23
Golang控制协程执行顺序方法详解
2024-02-20 13:00:21
在vue中利用全局路由钩子给url统一添加公共参数的例子
2024-04-28 10:55:44
sqlserver 游标的简单示例
2024-01-12 13:29:01
Tensorflow矩阵运算实例(矩阵相乘,点乘,行/列累加)
2023-12-19 04:07:42
![](https://img.aspxhome.com/file/2023/3/89343_0s.png)
默认Web字体样式
2009-11-24 12:37:00
python实现的系统实用log类实例
2022-08-02 18:50:57