当前位置: 首页 > news >正文

小程序 swiper滑动 层叠滑动效果

整个红色区域为可滑动区域,数字1区域为展示区域,数字2为下一个展示模块

<scroll-view class="h_scroll_horizontal" enhanced="ture" bind:touchend="touchEnd" bind:touchstart="touchStart"><view class="h_od_big"><swiper class="h_od_swiper"  current="{{orderIndex}}"><block wx:for="{{orderTip}}" wx:key="index"><swiper-item catchtouchmove="stopTouchMove"><view class="h_od_swiper_box">{{item}}</view></swiper-item></block></swiper><view class="h_od_gird_box"><view class="h_od_gird {{index==0?'h_od_gird_show':''}}" wx:for="{{orderTip2}}" wx:key="index" wx:if="{{index<3}}"  style='transform:translate({{index*15}}rpx,{{index*20}}rpx);z-index: {{-index}};height: {{index==0?index+1*228:228-15*index}}rpx;'>{{orderTip[orderIndex+1]}}</view></view></view></scroll-view>
.h_od_swiper {/* border: 1rpx solid black; */width: 450rpx;height: 228rpx;background: linear-gradient(180deg, #FFF6E3 0%, #FFE5D9 100%);border-radius: 12rpx;border: 1rpx solid #E08100;z-index: 0 !important;
}.h_od_swiper_box {width: 100%;height: 100%;padding: 24rpx 20rpx;}
.h_scroll_horizontal {/* border: 1rpx solid red; */width: 100%;margin-bottom: 30rpx;
}.h_od_big {display: flex;width: 100%;/* border: 1rpx solid #0064FF; */
}.h_od_gird_box {position: relative;/* border: 1rpx solid #0064FF; */margin-left: 15rpx;width: 185rpx;height: 228rpx;position: relative;display: flex;flex-direction: columnl;box-sizing: border-box;}.h_od_gird {position: absolute;left: 0;width: 100%;height: 100%;background: linear-gradient(180deg, #FFF6E3 0%, #FFE5D9 100%);border-radius: 12rpx;border: 1rpx solid #E08100;
}.h_od_gird_show {background: linear-gradient(180deg, #FFF6E3 0%, #FFE5D9 100%);left: 0rpx;position: absolute;z-index: 100;}
data: {orderTip: ['1', '2', '3', '4', '5', '6'],orderTip2: ['1', '2', '3', '4', '5', '6'],orderIndex: 0,flag: '',lastX: '',lastY: '',},/***   滑动开始*/touchStart(e) {let that = thisconsole.log(e)that.data.flag = 0;that.data.lastX = e.changedTouches[0].pageX;that.data.lastY = e.changedTouches[0].pageY;},/***   滑动结束*/touchEnd(e) {let that = thislet { flag, lastX, lastY, orderIndex, orderTip, orderTip2 } = that.dataif (flag !== 0) {return;}let currentX = e.changedTouches[0].pageX;let currentY = e.changedTouches[0].pageY;let tx = currentX - lastX;let ty = currentY - lastY;//左右方向偏移大于上下偏移认为是左右滑动if (Math.abs(tx) - Math.abs(ty) > 5) {// 向左滑动if (tx < 0) {// 如果到最右侧console.log('向左滑动');flag = 1;console.log(orderIndex, orderTip.length);if (orderIndex >= 0 && orderIndex < orderTip.length - 1) {console.log(orderTip2.length);orderTip2.pop()that.setData({orderIndex: orderIndex + 1,orderTip2: orderTip2})}// 向右滑动()} else if (tx > 0) {// 如果到最左侧flag = 2;console.log('向右滑动');console.log(orderIndex);if (orderIndex > 0) {orderTip2.push('')that.setData({orderIndex: orderIndex - 1,orderTip2: orderTip2})}}}//上下方向滑动else {if (ty < 0) {//向上滑动flag = 3;} else if (ty > 0) {//向下滑动flag = 4;}}//将当前坐标进行保存以进行下一次计算that.data.lastX = currentX;that.data.lastY = currentY;console.log('停止滑动', e)//停止滑动that.data.flag = 0;},/***   swiper Index*/swipertabb(e) {this.setData({orderIndex: e.detail.current})},

http://www.lryc.cn/news/207456.html

相关文章:

  • 【20年VIO梳理】
  • Java Object类详解
  • Unity 中忽略图片透明度的 Image 组件的修改版本
  • hibernate源码(1)--- schema创建
  • 数学与经济管理
  • 自动化测试系列 —— UI自动化测试
  • 眨个眼就学会了PixiJS
  • WORD中的表格内容回车行距过大无法调整行距
  • MySQL 高级函数整理
  • UG\NX二次开发 连接曲线、连结曲线 UF_CURVE_auto_join_curves
  • python爬虫入门(四)爬取猫眼电影排行(使用requests库和正则表达式)
  • Mybatis-Plus CRUD
  • 【强化学习】08——规划与学习(采样方法|决策时规划)
  • (链表) 25. K 个一组翻转链表 ——【Leetcode每日一题】
  • VisualStudio[WPF/.NET]基于CommunityToolkit.Mvvm架构开发
  • 深度学习_5_模型拟合_梯度下降原理
  • 大模型时代,AI如何成为数实融合的驱动力?
  • MS COCO数据集的评价标准以及不同指标的选择推荐(AP、mAP、MS COCO、AR、@、0.5、0.75、1、目标检测、评价指标)
  • css实现鼠标多样化
  • 21.2 Python 使用Scapy实现端口探测
  • Qt设计一个自定义的登录框窗口
  • 05 MIT线性代数-转置,置换,向量空间Transposes, permutations, spaces
  • [数据结构】二叉树
  • idea 中配置 maven
  • Python---for循环嵌套
  • 189. 轮转数组 --力扣 --JAVA
  • C# 使用waveIn实现声音采集
  • 长连接的原理
  • 软考系列(系统架构师)- 2015年系统架构师软考案例分析考点
  • 小程序开发——小程序的视图与渲染