底部3-5個選項的底部導航欄,目前在移動端上是主流布局之一
因此騰訊官方特地做了,可以通過設置,就可以做出了一個底部的導航欄
但是通過設置的這個底部的導航欄,功能上比較固定,它必須要設置與它對應的一個頁面,而且并不能滑動。
在業(yè)務上,有時候會比較限制,并不能完全滿足所需。
因此自定義就有這個必要性
下面介紹這個仿Android fragment可滑動的底部導航欄如何實現(xiàn)
下面介紹這個仿android fragment可滑動的底部導航欄如何實現(xiàn)
項目最終效果圖:
wxml:
-
<swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{winHeight - 51}}px" bindchange="bindChange">
-
-
-
<swiper-item>
-
<scroll-view class="hot-box" scroll-y="true" upper-threshold="50" lower-threshold="100" bindscrolltolower="scrolltolower">
-
-
-
<view class="themes-list">
-
<view class="themes-list-box" wx:for="{{datalists}}">
-
<view class="themes-list-main">
-
<view class="themes-list-name">{{item}}</view>
-
</view>
-
</view>
-
</view>
-
</scroll-view>
-
</swiper-item>
-
-
-
<swiper-item>
-
<scroll-view class="hot-box" scroll-y="true" upper-threshold="50" lower-threshold="100" bindscrolltolower="scrolltolower">
-
-
-
<view class="themes-list">
-
<view class="themes-list-box" wx:for="{{reslists}}">
-
<view class="themes-list-main">
-
<view class="themes-list-name">{{item}}</view>
-
</view>
-
</view>
-
</view>
-
</scroll-view>
-
</swiper-item>
-
-
-
<swiper-item>
-
<scroll-view class="hot-box" scroll-y="true" upper-threshold="50" lower-threshold="100" bindscrolltolower="scrolltolower">
-
-
-
<view class="themes-list">
-
<view class="themes-list-box" wx:for="{{datalists}}">
-
<view class="themes-list-main">
-
<view class="themes-list-name">{{item}}</view>
-
</view>
-
</view>
-
</view>
-
</scroll-view>
-
</swiper-item>
-
-
-
<swiper-item>
-
<scroll-view class="hot-box" scroll-y="true" upper-threshold="50" lower-threshold="100" bindscrolltolower="scrolltolower">
-
-
-
<view class="themes-list">
-
<view class="themes-list-box" wx:for="{{reslists}}">
-
<view class="themes-list-main">
-
<view class="themes-list-name">{{item}}</view>
-
</view>
-
</view>
-
</view>
-
</scroll-view>
-
</swiper-item>
-
</swiper>
-
-
-
<view class="swiper-tab">
-
<view class="swiper-tab-list {{currentTab==0 ? 'active' : ''}}" data-current="0" bindtap="swichNav">
-
<view class="swiper-tab-img"><image class="img" src="{{currentTab==0 ? iconlists[0].focus: iconlists[0].normal}}"></image></view>
-
<view>frag01</view>
-
</view>
-
<view class="swiper-tab-list {{currentTab==1 ? 'active' : ''}}" data-current="1" bindtap="swichNav">
-
<view class="swiper-tab-img"><image class="img" src="{{currentTab==1 ? iconlists[1].focus: iconlists[1].normal}}"></image></view>
-
<view>frag02</view>
-
</view>
-
<view class="swiper-tab-list {{currentTab==2 ? 'active' : ''}}" data-current="2" bindtap="swichNav">
-
<view class="swiper-tab-img"><image class="img" src="{{currentTab==2 ? iconlists[2].focus: iconlists[2].normal}}"></image></view>
-
<view>frag03</view>
-
</view>
-
<view class="swiper-tab-list {{currentTab==3 ? 'active' : ''}}" data-current="3" bindtap="swichNav">
-
<view class="swiper-tab-img"><image class="img" src="{{currentTab==3 ? iconlists[3].focus: iconlists[3].normal}}"></image></view>
-
<view>frag04</view>
-
</view>
-
</view>
wxss:
-
-
.swiper-box {
-
display: block;
-
height: 100%;
-
width: 100%;
-
overflow: hidden;
-
}
-
.hot-box {
-
display: block;
-
height: 100%;
-
font-family: Helvetica;
-
}
-
-
.themes-list {
-
background: #fff;
-
display: block;
-
margin-bottom: 20px;
-
}
-
.themes-list-box {
-
display: block;
-
position: relative;
-
padding: 16px 20px;
-
border-bottom: 1px solid #f2f2f2;
-
}
-
.themes-list-main {
-
margin-left: 1px;
-
}
-
.themes-list-name {
-
font-size: 14px;
-
color: #444;
-
height: 20px;
-
line-height: 20px;
-
overflow: hidden;
-
}
-
-
.swiper-tab {
-
height: 50px;
-
background: #fff;
-
display: flex;
-
position: relative;
-
z-index: 2;
-
flex-direction: row;
-
justify-content: center;
-
align-items: center;
-
border-top: 1px solid #ccc;
-
}
-
.swiper-tab-list {
-
margin: 0 20px;
-
padding: 0 4px;
-
font-size: 28rpx;
-
font-family: Helvetica;
-
}
-
.active {
-
-
color: #FFCC00;
-
}
-
.swiper-tab-img {
-
text-align: center;
-
}
-
.img {
-
width:23px;
-
height: 23px;
-
}
js:
-
Page( {
-
data: {
-
winWidth: 0,
-
winHeight: 0,
-
currentTab: 0,
-
datalists : [
-
"習近平主持中央財經(jīng)領導小組第十五次會議",
-
"李克強打叉的“萬里審批圖”成歷史",
-
"新疆自治區(qū)舉行反恐維穩(wěn)誓師大會",
-
"朝鮮代表團抵達馬來西亞處理金正男遇害案",
-
"寶馬車禍案肇事者二次精神鑒定:案發(fā)為精神病狀態(tài)",
-
"朝鮮代表團抵達馬來西亞處理金正男遇害案",
-
"寶馬車禍案肇事者二次精神鑒定:案發(fā)為精神病狀態(tài)",
-
"朝鮮代表團抵達馬來西亞處理金正男遇害案",
-
"寶馬車禍案肇事者二次精神鑒定:案發(fā)為精神病狀態(tài)",
-
"朝鮮代表團抵達馬來西亞處理金正男遇害案",
-
"寶馬車禍案肇事者二次精神鑒定:案發(fā)為精神病狀態(tài)",
-
"砸鍋賣鐵!索尼是在走向毀滅 還是在奔向新生?"
-
],
-
reslists:["hello","thank you for your read","if u feel good","can u give me good?"],
-
iconlists:[
-
{normal:"../../images/wp.png",focus:"../../images/wpselect.png"},
-
{normal:"../../images/ss.png",focus:"../../images/ssselect.png"},
-
{normal:"../../images/hc.png",focus:"../../images/hcselect.png"},
-
{normal:"../../images/my.png",focus:"../../images/myselect.png"},
-
]
-
},
-
onLoad: function( options ) {
-
var that = this;
-
-
wx.getSystemInfo( {
-
success: function( res ) {
-
that.setData( {
-
winWidth: res.windowWidth,
-
winHeight: res.windowHeight
-
});
-
}
-
});
-
},
-
-
-
-
bindChange: function( e ) {
-
var that = this;
-
that.setData( { currentTab: e.detail.current });
-
},
-
-
-
-
swichNav: function( e ) {
-
console.log(e)
-
var that = this;
-
if( this.data.currentTab === e.currentTarget.dataset.current ) {
-
-
return false;
-
} else {
-
that.setData( {
-
currentTab: e.currentTarget.dataset.current
-
})
-
}
-
-
}
-
})
|