微信小程序中的页面左右滑动效果怎样做?
Admin 2021-10-30 群英技术资讯 2232 次浏览
这篇文章给大家分享的是微信小程序中的页面左右滑动效果的实现,这个效果的应用还是比较多的,小编觉得挺实用的,因此分享给大家做个参考,文中示例代码介绍的非常详细,感兴趣的朋友接下来一起跟随小编看看吧。
效果:
wxml文件
<view bindtouchmove="tap_drag" bindtouchend="tap_end" bindtouchstart="tap_start" class="page-top
{{open ? ['c-state','cover'] : ''}} "> <view bindtap="tap_ch" style="{{open ? 'color: red;font-weight: bold;' : ''}}">{{open ? '手指左滑' : '手指右滑'}}</view> <view class='content'> <text>我是内容我是内容!</text> </view> </view>
js文件
data: { open: false, // mark 是指原点x轴坐标 mark: 0, // newmark 是指移动的最新点的x轴坐标 newmark: 0, istoright: true }, // 点击左上角小图标事件 tap_ch: function(e) { if (this.data.open) { this.setData({ open: false }); } else { this.setData({ open: true }); } }, tap_start: function(e) { // touchstart事件 // 把手指触摸屏幕的那一个点的 x 轴坐标赋值给 mark 和 newmark this.data.mark = this.data.newmark = e.touches[0].pageX; }, tap_drag: function(e) { // touchmove事件 this.data.newmark = e.touches[0].pageX; // 手指从左向右移动 if (this.data.mark < this.data.newmark) { this.istoright = true; } // 手指从右向左移动 if (this.data.mark > this.data.newmark) { this.istoright = false; } this.data.mark = this.data.newmark; }, tap_end: function(e) { // touchend事件 this.data.mark = 0; this.data.newmark = 0; // 通过改变 opne 的值,让主页加上滑动的样式 if (this.istoright) { this.setData({ open: true }); } else { this.setData({ open: false }); } },
wxss文件
/* 全局样式 */ page, .page { height: 100%; font-family: 'PingFang SC', 'Helvetica Neue', Helvetica, 'Droid Sans Fallback', 'Microsoft Yachei', sans-serif; } /* 侧边栏样式 */ .page-slidebar { height: 100%; width: 750rpx; position: fixed; background-color:white; z-index: 0; } /* 控制侧边栏的内容距离顶部的距离 */ .page-content { padding-top: 60rpx; } /* 侧边栏内容的 css 样式 */ .wc { color:black; padding: 30rpx 0 30rpx 150rpx; border-bottom: 1px solid #eee; } /* 当屏幕向左滑动,出现侧边栏的时候,主页的动画样式 */ /* scale:取值范围 0~1 ,表示屏幕大小是原来的百分之几,可以自己修改成 0.8 试下*/ /* translate(60%,0%) 表示向左滑动的时候,侧边栏占用平时的宽度为 60% */ /* translate(-60%,0%) 表示向右滑动的时候,侧边栏占用平时的宽度为 60% */ .c-state { transform: rotate(0deg) scale(1) translate(60%, 0%); -webkit-transform: rotate(0deg) scale(1) translate(60%, 0%); } /* 主页样式 */ .page-top { height: 100%; position: fixed; width: 750rpx; background-color:white; z-index: 0; transition: All 0.4s ease; -webkit-transition: All 0.4s ease; } /* 左上角图标的样式 */ .page-top image { position: absolute; width: 68rpx; height: 68rpx; left: 20rpx; top: 20rpx; } /* 遮盖层样式 */ .cover{ width: 100%; height: 100%; background-color:gray; opacity: 0.5; z-index: 9000; } .content{ margin-top: 100rpx; }
关于微信小程序中的页面左右滑动效果的实现就介绍到这,本文代码仅供参考,感兴趣的朋友可以了解看看,希望能对大家有帮助,想要了解更多大家可以关注其它的相关文章。
文本转载自脚本之家
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
本文主要给大家分享的时候JS等于运算符,很多朋友觉得JS等于运算符很好用,可能会出现滥用的情况,但其实等于运算符使用有些问题是需要了解的,下面我们就来看看。
JavaScript事件循环是什么?对新手来说,可能不是很了解JavaScript事件循环,因此这篇文章就给大家来简单的介绍一下,另外下文还介绍了node.js的优缺点等等,有这方面学习需要的朋友就往下看吧。
本文实例讲述了JS运算符简单用法。分享给大家供大家参考,对大家学习和工作有一定的帮助和参考价值,具体如下:
这篇文章主要为大家介绍了JS数组中常用的方法技巧,学会了你就在进阶成为大佬的道路上又迈进了一步,希望能够有所帮助,祝大家多多进步
这篇文章主要为大家详细介绍了jquery插件实现悬浮的菜单,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008