微信小程序之選項卡的實現(xiàn)方法
微信小程序之選項卡的實現(xiàn)方法
前言:
從事前端的同學(xué)們一定不會對選項卡陌生,不管是自己原生寫的,還是各個UI框架里帶的,我想大家都使用過很多選項卡,對選項卡的原理也足夠清楚了,下面我們來在微信小程序里實現(xiàn)選項卡的功能。
微信小程序里沒有自帶選項卡組件,但是卻帶有swiper組件,所以,我們便利用swiper來實現(xiàn)選項卡的功能。
先看效果圖:


實現(xiàn)代碼:
頁面代碼:
<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>
<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>
js代碼:
var app=getApp()
Page({
data:{
currentTab:0
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
},
//滑動切換
swiperTab:function( e ){
var that=this;
that.setData({
currentTba: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
})
}
}
})
css代碼:
.swiper-tab{
width: 100%;
border-bottom: 2rpx solid #ccc;
text-align: center;
height: 88rpx;
line-height: 88rpx;
font-weight: bold;
}
.swiper-tab-item{
display: inline-block;
width: 33.33%;
color:red;
}
.active{
color:aqua;
border-bottom: 4rpx solid red;
}
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
- 微信小程序開發(fā)之選項卡(窗口底部TabBar)頁面切換
- 微信小程序開發(fā)之實現(xiàn)選項卡(窗口頂部TabBar)頁面切換
- 微信小程序?qū)崿F(xiàn)單選選項卡切換效果
- 微信小程序 選項卡的簡單實例
- 微信小程序 tabs選項卡效果的實現(xiàn)
- 微信小程序?qū)崿F(xiàn)選項卡功能
- 微信小程序 實現(xiàn)tabs選項卡效果實例代碼
- 微信小程序?qū)崿F(xiàn)頂部選項卡(swiper)
- 微信小程序?qū)崿F(xiàn)導(dǎo)航欄選項卡效果
- 微信小程序開發(fā)之Tabbar實例詳解
- 微信小程序tabBar用法實例詳解
- 微信小程序開發(fā)實現(xiàn)的選項卡(窗口頂部/底部TabBar)頁面切換功能圖文詳解
相關(guān)文章
JavaScript實際應(yīng)用:innerHTMl和確認提示的使用
JavaScript實際應(yīng)用:innerHTMl和確認提示的使用...2006-06-06
JavaScript國際化API格式化數(shù)據(jù)Intl.NumberFormat使用講解
這篇文章主要為大家介紹了JavaScript國際化API格式化數(shù)據(jù)Intl.NumberFormat使用講解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06
mini?webpack打包基礎(chǔ)解決包緩存和環(huán)依賴
這篇文章主要為大家介紹了mini?webpack打包基礎(chǔ)解決包緩存和環(huán)依賴示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09
ECharts框架Sunburst拖拽功能實現(xiàn)方案詳解
這篇文章主要為大家介紹了ECharts框架Sunburst拖拽功能實現(xiàn)方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12

