赞
踩
使用微信小程序实现左右滑动功能,自定义顶部图案,点击文字滑动和手势触屏滑动,功能简单,具体实现代码如下所示:
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呦。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。