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


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

    1. <scroll-view class="h_scroll_horizontal" enhanced="ture" bind:touchend="touchEnd" bind:touchstart="touchStart">
    2. <view class="h_od_big">
    3. <swiper class="h_od_swiper" current="{{orderIndex}}">
    4. <block wx:for="{{orderTip}}" wx:key="index">
    5. <swiper-item catchtouchmove="stopTouchMove">
    6. <view class="h_od_swiper_box">
    7. {{item}}
    8. </view>
    9. </swiper-item>
    10. </block>
    11. </swiper>
    12. <view class="h_od_gird_box">
    13. <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]}}
    14. </view>
    15. </view>
    16. </view>
    17. </scroll-view>
    1. .h_od_swiper {
    2. /* border: 1rpx solid black; */
    3. width: 450rpx;
    4. height: 228rpx;
    5. background: linear-gradient(180deg, #FFF6E3 0%, #FFE5D9 100%);
    6. border-radius: 12rpx;
    7. border: 1rpx solid #E08100;
    8. z-index: 0 !important;
    9. }
    10. .h_od_swiper_box {
    11. width: 100%;
    12. height: 100%;
    13. padding: 24rpx 20rpx;
    14. }
    15. .h_scroll_horizontal {
    16. /* border: 1rpx solid red; */
    17. width: 100%;
    18. margin-bottom: 30rpx;
    19. }
    20. .h_od_big {
    21. display: flex;
    22. width: 100%;
    23. /* border: 1rpx solid #0064FF; */
    24. }
    25. .h_od_gird_box {
    26. position: relative;
    27. /* border: 1rpx solid #0064FF; */
    28. margin-left: 15rpx;
    29. width: 185rpx;
    30. height: 228rpx;
    31. position: relative;
    32. display: flex;
    33. flex-direction: columnl;
    34. box-sizing: border-box;
    35. }
    36. .h_od_gird {
    37. position: absolute;
    38. left: 0;
    39. width: 100%;
    40. height: 100%;
    41. background: linear-gradient(180deg, #FFF6E3 0%, #FFE5D9 100%);
    42. border-radius: 12rpx;
    43. border: 1rpx solid #E08100;
    44. }
    45. .h_od_gird_show {
    46. background: linear-gradient(180deg, #FFF6E3 0%, #FFE5D9 100%);
    47. left: 0rpx;
    48. position: absolute;
    49. z-index: 100;
    50. }
    1. data: {
    2. orderTip: ['1', '2', '3', '4', '5', '6'],
    3. orderTip2: ['1', '2', '3', '4', '5', '6'],
    4. orderIndex: 0,
    5. flag: '',
    6. lastX: '',
    7. lastY: '',
    8. },
    9. /**
    10. * 滑动开始
    11. */
    12. touchStart(e) {
    13. let that = this
    14. console.log(e)
    15. that.data.flag = 0;
    16. that.data.lastX = e.changedTouches[0].pageX;
    17. that.data.lastY = e.changedTouches[0].pageY;
    18. },
    19. /**
    20. * 滑动结束
    21. */
    22. touchEnd(e) {
    23. let that = this
    24. let { flag, lastX, lastY, orderIndex, orderTip, orderTip2 } = that.data
    25. if (flag !== 0) {
    26. return;
    27. }
    28. let currentX = e.changedTouches[0].pageX;
    29. let currentY = e.changedTouches[0].pageY;
    30. let tx = currentX - lastX;
    31. let ty = currentY - lastY;
    32. //左右方向偏移大于上下偏移认为是左右滑动
    33. if (Math.abs(tx) - Math.abs(ty) > 5) {
    34. // 向左滑动
    35. if (tx < 0) {
    36. // 如果到最右侧
    37. console.log('向左滑动');
    38. flag = 1;
    39. console.log(orderIndex, orderTip.length);
    40. if (orderIndex >= 0 && orderIndex < orderTip.length - 1) {
    41. console.log(orderTip2.length);
    42. orderTip2.pop()
    43. that.setData({
    44. orderIndex: orderIndex + 1,
    45. orderTip2: orderTip2
    46. })
    47. }
    48. // 向右滑动()
    49. } else if (tx > 0) {
    50. // 如果到最左侧
    51. flag = 2;
    52. console.log('向右滑动');
    53. console.log(orderIndex);
    54. if (orderIndex > 0) {
    55. orderTip2.push('')
    56. that.setData({
    57. orderIndex: orderIndex - 1,
    58. orderTip2: orderTip2
    59. })
    60. }
    61. }
    62. }
    63. //上下方向滑动
    64. else {
    65. if (ty < 0) {
    66. //向上滑动
    67. flag = 3;
    68. } else if (ty > 0) {
    69. //向下滑动
    70. flag = 4;
    71. }
    72. }
    73. //将当前坐标进行保存以进行下一次计算
    74. that.data.lastX = currentX;
    75. that.data.lastY = currentY;
    76. console.log('停止滑动', e)
    77. //停止滑动
    78. that.data.flag = 0;
    79. },
    80. /**
    81. * swiper Index
    82. */
    83. swipertabb(e) {
    84. this.setData({
    85. orderIndex: e.detail.current
    86. })
    87. },

  • 相关阅读:
    zabbix监控脑裂
    算法笔试ACM模式如何输入
    【DDD】学习笔记-发布者—订阅者模式
    SpringBoot中的yml文件中读取自定义配置信息
    【论文阅读】基于深度学习的R-134a气泡检测和分析方法—用于地热应用
    硬核java hook(直接改jdk)
    前端Vue怎么获取登录的用户名或用户id
    NIO教程
    numpy 下载安装
    “2024成都国际电子信息产业展览会”新西部、新重构、新机遇
  • 原文地址:https://blog.csdn.net/qq706352062/article/details/133987372