微信小程序之導(dǎo)航滑塊視圖容器功能的實現(xiàn)代碼(簡單兩步)
先看效果圖:


這個滑塊除了可以點擊上方的導(dǎo)航,還可以左右切換頁面,隨之導(dǎo)航也跟這切換。
實現(xiàn)步驟:
- 編寫滑塊視圖代碼
- 編寫邏輯代碼
wxml:
<view class="content">
<view class="title">
<view class="{{currentTab==0?'select':'default'}}" data-current="0" bindtap="switchNav">關(guān)注</view>
<view class="{{currentTab==1?'select':'default'}}" data-current="1" bindtap="switchNav">新鮮</view>
<view class="{{currentTab==2?'select':'default'}}" data-current="2" bindtap="switchNav">推薦</view>
</view>
<swiper class="swiper" bindchange="swiperchange" current="{{currentTab}}" style="height:{{winHeight}}px">
<swiper-item item-id="{{item.id}}">
關(guān)注
</swiper-item>
<swiper-item item-id="{{item.id}}">
新鮮
</swiper-item>
<swiper-item item-id="{{item.id}}">
推薦
</swiper-item>
</swiper>
</view>
wxss:
.title{
display: flex;
flex-direction: row;
width: 100%;
background-color: #ff99cc;
height: 100rpx;
position: fixed;
z-index: 9999999999999;
}
.select{
width: 33%;
text-align: center;
height: 45px;
line-height: 45px;
color: white;
border-bottom: 5rpx solid #ff99cc;
}
.default{
margin:0 auto;
padding:15px;
color: #666;
}
.swiper{
margin-top: 100rpx;
}
js:
data: {
currentTab:1,
winWidth:0,
winHeight:0
},
onLoad: function (options) {
wx.getSystemInfo({
complete: (res) => {
this.setData({
winWidth:res.windowWidth,
winHeight:res.windowHeight
})
},
})
},
switchNav(e){
console.log(e)
if(this.data.currentTab==e.target.dataset.current){
return false
}else{
this.setData({
currentTab:e.target.dataset.current
})
}
},
swiperchange(e){
this.setData({
currentTab:e.detail.current
})
},
總結(jié)
到此這篇關(guān)于微信小程序之導(dǎo)航滑塊視圖容器功能的實現(xiàn)代碼(簡單兩步)的文章就介紹到這了,更多相關(guān)微信小程序滑塊視圖容器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Javascript連接數(shù)據(jù)庫查詢并插入數(shù)據(jù)
這篇文章主要介紹了Javascript連接數(shù)據(jù)庫查詢并插入數(shù)據(jù),下面文章圍繞主題展開詳細內(nèi)容,具有一的參考價值,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助2022-03-03
js獲得指定控件輸入光標的坐標兼容IE,Chrome,火狐等多種主流瀏覽器
js獲得指定控件光標的坐標,兼容IE,Chrome,火狐等多種主流瀏覽器,實現(xiàn)代碼及調(diào)用代碼如下,感興趣的朋友可以參考下哈,希望對你有所幫助2013-05-05
JavaScript中Async/Await通過同步的方式實現(xiàn)異步的方法介紹
在JavaScript的異步編程中,我們經(jīng)常使用回調(diào)函數(shù)、Promise和 Async/Await來解決異步操作的問題,Async/Await 又是Promise的語法糖,它的出現(xiàn)讓異步編程變得更加直觀和易于理解,本文將詳細講解Async/Await如何通過同步的方式實現(xiàn)異步2023-06-06
TypeScript調(diào)整數(shù)組元素順序算法
數(shù)組類型在TS中可以使用多種方式,比較靈活,下面這篇文章主要給大家介紹了關(guān)于TypeScript調(diào)整數(shù)組元素順序算法的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-04-04

