码迷,mamicode.com
首页 > 微信 > 详细

小程序之 tab切换(选项卡)

时间:2018-10-16 11:54:22      阅读:777      评论:0      收藏:0      [点我收藏+]

标签:text   relative   row   tail   cli   change   active   between   targe   

好久没有写东西了   今天写一个简单的东西

小程序tab切换 (选项卡功能)

 

.wxml

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

<swiper current="{{currentTab}}" bindchange="swiperTab" style="height:{{swiperHeight}}rpx;">
  <swiper-item>
    <view class=ycy>
      <text>111111</text>
    </view>
  </swiper-item>

  <swiper-item>
    <view class=ycy>
      <text>222222</text>
    </view>
  </swiper-item>
</swiper>

 

.js

Page({
  data: {
    currentTab: 0,
  },
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
})

 

.wxss

.swiper-tab{
    width: 100%;
    border-bottom: 1rpx solid #eee;
    text-align: center;
    height: 90rpx;
    line-height: 90rpx;
    display: flex;
    flex-flow: row;
    font-size: 32rpx;
    justify-content: space-between;
}
.swiper-tab-item{
    width: 50%; 
    color:#434343;
}
.active{
  color:#F65959;
  border-bottom: 2rpx solid #F65959;
}
.ycy{
  width: 100%;
  display: flex;
  height: 95rpx;
  border-bottom: 1px solid #eee;
  position: relative;
}

 

小程序之 tab切换(选项卡)

标签:text   relative   row   tail   cli   change   active   between   targe   

原文地址:https://www.cnblogs.com/liancat/p/9796907.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!