本篇文章给大家带来的内容是关于微信小程序实现一个简单的Tab可滑动的切换方式(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
最近一直在做小程序项目,对于不同需求来说真是烦不胜烦,之前做的订单页来说只需要可点击切换就可以,但是在后期的迭代中提到要求可滑动切换,下面我自己整理了一套比较简单暴力的滑动切换方式,与大家共享一下,下面有效果图。(菜鸟上路,不喜勿喷):
.wxml
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 | <!--pages/mine/order/order.wxml-->
<view class=& #39;order'>
<view class= "swiper-tab" >
<view class= "swiper-tab-item {{currentTab==0?'active':''}}" data-current= "0" bindtap= "clickTab" >代付款</view>
<view class= "swiper-tab-item {{currentTab==1?'active':''}}" data-current= "1" bindtap= "clickTab" >代发货</view>
<view class= "swiper-tab-item {{currentTab==2?'active':''}}" data-current= "2" bindtap= "clickTab" >待收货</view>
<view class= "swiper-tab-item {{currentTab==3?'active':''}}" data-current= "3" bindtap= "clickTab" >待评价</view>
<view class= "swiper-tab-item {{currentTab==4?'active':''}}" data-current= "4" bindtap= "clickTab" >退款/售后</view>
</view>
<swiper current= "{{currentTab}}" duration= "300" bindchange= "swiperTab" >
<swiper-item>
<view>代付款</view>
</swiper-item>
<swiper-item>
<view>代发货</view>
</swiper-item>
<swiper-item>
<view>待收货</view>
</swiper-item>
<swiper-item>
<view>待评价</view>
</swiper-item>
<swiper-item>
<view>退款/售后</view>
</swiper-item>
</swiper>
</view>
|
.wxss
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 | .swiper-tab {
width: 100%;
border-bottom: 2rpx solid #ccc;
text-align: center;
height: 88rpx;
line-height: 88rpx;
display: flex;
flex-flow: row;
justify-content: space-between;
}
.swiper-tab-item {
width: 30%;
color: #434343;
font-size: 28rpx;
}
.active {
color: #f65959;
border-bottom: 4rpx solid #f65959;
}
swiper {
text-align: center;
background-color: #fff
}
|
.js
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 | Page({
data: {
currentTab: 0
},
onLoad: function (options) {
},
swiperTab: function (e) {
this .setData({
currentTab: e.detail.current
});
},
clickTab: function (e) {
if ( this .data.currentTab === e.target.dataset.current) {
return false ;
} else {
this .setData({
currentTab: e.target.dataset.current
})
}
}
})
|
效果图:
在wxml部分其实可以用个wx:for 来做。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~