小程序tab选项卡

 

造轮子啦 ! 造轮子啦!!造轮子啦!!!重要的事情说三遍!!!!

wxml:

<view class='tab'>

<view class='{{tag == index?"true":"false"}}' wx:for='{{4}}' wx:key='key' data-index='{{index}}' catchtap='btn'>页面{{index}}</view>

</view>

 

<swiper current="{{tag}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="bindChange">

<!-- 页面一 -->

<swiper-item>

<scroll-view class='scroll' scroll-y='true'>

页面一

</scroll-view>

</swiper-item>

<!-- 页面二 -->

<swiper-item>

<scroll-view style='height:100%;' scroll-y='true'>

页面二

</scroll-view>

</swiper-item>

<!-- 页面三 -->

<swiper-item>

<scroll-view style='height:100%;' scroll-y='true'>

页面三

</scroll-view>

</swiper-item>

<!-- 页面四 -->

<swiper-item>

<scroll-view style='height:100%;' scroll-y='true'>

页面四

</scroll-view>

</swiper-item>

</swiper>

 

wxss:

page {

overflow: hidden;

}

 

.tab {

width: 95%;

height: 80rpx;

margin: 0 auto;

display: flex;

justify-content: space-around;

}

 

.true {

width: 20%;

height: 80rpx;

line-height: 80rpx;

text-align: center;

color: orange;

border-bottom: 5rpx solid orange;

font-size: 35rpx;

}

 

.false {

width: 20%;

height: 80rpx;

line-height: 80rpx;

text-align: center;

font-size: 33rpx;

}

 

.swiper-box {

display: block;

height: 100%;

width: 100%;

overflow: hidden;

text-align: center;

background: #ddd;

margin-top: 10rpx;

}

 

js:

Page({

 

/**

* 页面的初始数据

*/

data: {

tag: 0,

},

 

/**

* 生命周期函数--监听页面加载

*/

onLoad: function(e) {

var that = this

/** 获取系统信息 */

wx.getSystemInfo({

success: function(res) {

that.setData({

winWidth: res.windowWidth,

winHeight: res.windowHeight

});

}

});

},

// 点击事件

btn: function(e) {

var that = this;

console.log(e.currentTarget.dataset.index, "点击")

var tag = e.currentTarget.dataset.index;

// console.log(tag, "e")

that.setData({

tag: tag,

})

 

},

// 滑动切换tab

bindChange: function(e) {

console.log(e, "滑动")

var that = this;

that.setData({

tag: e.detail.current

});

 

},

})

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值