微信小程序之Tab切换

wxml:

<view>

<view class='swiper-tab'>

<view class="swiper-tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="clickTab">1</view>

<view class="swiper-tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="clickTab">2</view>

<view class="swiper-tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="clickTab">3</view>

<view class="swiper-tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="clickTab">4</view>

</view>

<swiper class='swiper' current='{{currentTab}}' duration="300" bindchange="bindchange">

<view >

<swiper-item>

<scroll-view scroll-y="true">

<view class='gaodu'>第一页</view>

<view class='gaodu'>第一页</view>

<view class='gaodu'>第一页</view>

<view class='gaodu'>第一页</view>

<view class='gaodu'>显示</view>

</scroll-view>

</swiper-item>

</view>

<swiper-item>

<scroll-view scroll-y="true">

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

<view class='gaodu'>第二页</view>

</scroll-view>

</swiper-item>

<swiper-item>

<scroll-view scroll-y="true">

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

<view class='gaodu'>第三页</view>

</scroll-view>

</swiper-item>

<swiper-item>

<scroll-view scroll-y="true">

<view class='gaodu'>第四页</view>

<view class='gaodu'>第四页</view>

<view class='gaodu'>第四页</view>

<view class='gaodu'>第四页</view>

<view class='gaodu'>第四页</view>

<view class='gaodu'>第四页</view>

<view class='gaodu'>第四页</view>

<view class='gaodu'>1第四页</view>

<view class='gaodu'>0</view>

</scroll-view>

</swiper-item>

</swiper>

</view>

wxss:

.swiper-tab{

display: flex;

height: 80rpx;

line-height: 80rpx;

width: 100%;

position:fixed;

top:0;

z-index: 100;

background: #fff;

}

.swiper-tab-item{

flex: 1;

text-align: center;

border-bottom: 1rpx solid #eee;

}

.active{

color: blue;

position: relative;

}

.swiper-tab-item.active:after{

content: "";

display: block;

height: 6rpx;

width: 60rpx;

background: #4675F9;

position: absolute;

bottom: 0;

left: 65rpx;

border-radius: 16rpx;

}

.swiper{

width: 100%;

height: 100%;

display: flex;

position: fixed;

top:80rpx;

}

scroll-view{

width: 100%;

height: 93%;/*动态高度*/

}

.gaodu{

height: 100rpx;

background: rgb(196, 248, 255);

text-align: center;

line-height: 100rpx;

border-bottom: 1rpx solid #4675F9;

}

js:

Page({

data: {

currentTab: 0 //预定的位置

},

//点击滑动

bindchange: function (e) {

let that = this;

that.setData({

currentTab: e.detail.current

})

},

//点击切换,滑块index赋值

clickTab: function (e) {

let that = this;

if (that.data.currentTab === e.currentTarget.dataset.current) {

return false;

} else {

that.setData({

currentTab: e.currentTarget.dataset.current

})

}

}

})

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值