小程序tab切換效果

小程序?qū)崿F(xiàn)tab切換很簡單,只需要完成兩部分。
1.頁面
2.js觸發(fā)時間

先上效果:

image.png

接下來介紹頁面代碼:

控制切換的Tab

<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>

要切換的內(nèi)容

<view class = "{{currentTab == 0 ? 'show':'hidden'}}" >
    <scroll-view>
      <text>暫無內(nèi)容1</text>
    </scroll-view>
  </view>
  <view class = "{{currentTab == 1 ? 'show':'hidden'}}" >
    <scroll-view>
      <text>暫無內(nèi)容2</text>
    </scroll-view>
  </view>
  <view class = "{{currentTab == 2 ? 'show':'hidden'}}">
    <scroll-view>
      <text>暫無內(nèi)容3</text>
    </scroll-view>
  </view>

js觸發(fā)事件

//點擊切換
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
      })
    }

頁面樣式

/* pages/about/about.wxss */
.about_page{
  margin: 0 10px;
}
.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;
    color: #ccc;
    font-size: 16px;
}
.swiper-tab-item{
    width: 30%; 
    color:#434343;
}
.active{
    color:#F65959;
    /* border-bottom: 4rpx solid #F65959; */
    font-size: 16px;
    font-weight: bold;
}
.juzhong{
  margin: 0 auto;
}
.domain{
  background-color: #fff;
  height: 100%;
  margin:0 10px;
}
.show{
  display: block;
}
.hidden{
  display: none;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容