当前位置:   article > 正文

微信小程序简单实现手势左右滑动和点击滑动步骤条功能_微信小程序左右滑动代码实现

微信小程序左右滑动代码实现

使用微信小程序实现左右滑动功能,自定义顶部图案,点击文字滑动和手势触屏滑动,功能简单,具体实现代码如下所示:
滑动示例

1、wxss代码:

/* 步骤条 */
.tab-box {
  display: flex;
  flex-direction: row;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 999;
  background-color: #EEEEEE;
  padding: 15rpx 20rpx;
}

.radius-a {
  width: 34%;
  border-radius: 5rpx 0 0 5rpx;
}

.width-2{
  width: 28%;
}

.radius-b {
  width: 28%;
  border-radius: 0 5rpx 5rpx 0;
}

.rule-a {
  height: 80rpx;
  background-color: #44ADFB;
  color: white;
  line-height: 80rpx;
  text-align: center;
  font-size: 32rpx;
  font-weight: bold;
}

.rule-b {
  width: 0;
  height: 0;
  border-top: 40rpx solid transparent;
  border-bottom: 40rpx solid transparent;
  border-left: 20rpx solid #44ADFB;
}

.rule-c {
  position: relative;
  width: 0;
  height: 0;
  border-left: 40rpx solid transparent;
  border-bottom: 80rpx solid #44ADFB;
}

.rule-c::after {
  content: "";
  position: absolute;
  top: 0;
  left: -40rpx;
  width: 0;
  height: 0;
  border-left: 40rpx solid transparent;
  border-top: 80rpx solid #44ADFB;
}

.blue {
  color: #fff;
  background-color: #44ADFB;
}

.gray {
  color: #606266;
}

.box{
  margin-top: 120rpx;
  text-align: center;
  font-size: 32rpx;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78

2、wxml代码:

<view class="tab-box">
  <view class="rule-a radius-a {{currentVal == 0 ? 'blue' : 'gray'}}" bindtap="changeTabs" data-index="0">第一步</view>
  <view class="rule-b"></view>
  <view class="rule-c"></view>
  <view class="rule-a width-2 {{currentVal == 1 ? 'blue' : 'gray'}}" bindtap="changeTabs" data-index="1">第二步</view>
  <view class="rule-b"></view>
  <view class="rule-c"></view>
  <view class="rule-a radius-b {{currentVal == 2 ? 'blue' : 'gray'}}" bindtap="changeTabs" data-index="2">第三步</view>
</view>
<view class="box">
  <swiper current="{{currentVal}}" circular="true" bindchange="swiperChang">
    <!--第一步 -->
    <swiper-item>
      示例一界面内容
    </swiper-item>
    <!-- 第二步 -->
    <swiper-item>
      示例二界面内容
    </swiper-item>
    <!-- 第三步 -->
    <swiper-item>
      示例三界面内容
    </swiper-item>
  </swiper>
</view>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

3、js代码:

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentVal: 0,
  },
  //点击顶部tab切换
  changeTabs: function (e) {
    this.setData({
      currentVal: e.currentTarget.dataset.index
    });
  },
  // 滑动监听
  swiperChang: function (e) {
    this.setData({
      currentVal: e.detail.current
    });
  },
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

代码简洁,适合初学者,如有不恰当的地方,多多包涵,欢迎指教批评。。。更多微信小程序示例,进我主页,不定期分享最简单的demo呦。。。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/287514
推荐阅读
相关标签
  

闽ICP备14008679号