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

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

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;
}

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>

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
    });
  },
})

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

  • 10
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三脚猫的喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值