微信小程序?qū)崿F(xiàn)YDUI的ScrollNav組件
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)滾動(dòng)導(dǎo)航效果的具體代碼,供大家參考,具體內(nèi)容如下
DEMO下載
效果圖

實(shí)現(xiàn)原理
采用雙 scroll-view 組件實(shí)現(xiàn)雙滾動(dòng)!
WXML
<!--導(dǎo)航滾動(dòng) -->
<scroll-view class="tui-city-scroll" scroll-x="true" scroll-into-view="NAV{{status}}" scroll-with-animation="true">
<text bindtap="getStatus" id="NAV{{index}}" class="tui-nav-li {{index === status ? 'tui-nav-active' : ''}}" data-index="{{index}}" wx:for="{{navList}}">{{item}}</text>
</scroll-view>
<!--列表滾動(dòng)區(qū) -->
<view class="tui-fixed-y">
<scroll-view class="tui-city-scroll-y" scroll-y="true" scroll-into-view="NAV{{status}}" scroll-with-animation="true">
<view wx:for="{{navList}}">
<view id="NAV{{index}}" class="tui-list-head">{{item}}</view>
<view class="tui-list-li">{{item}} 列表 {{index}}</view>
</view>
</scroll-view>
</view>
WXSS
.tui-fixed-x{
width: 100%;
position: fixed;
top: 0;
left: 0;
}
.tui-city-scroll{
height: 80rpx;
line-height: 80rpx;
width: 100%;
white-space: nowrap;
}
.tui-nav-li{
font-size: 30rpx;
padding: 0 8rpx;
}
.tui-nav-li:first-child{padding-left: 16rpx;}
.tui-nav-li:last-child{padding-right: 16rpx;}
.tui-nav-active{color: red;}
.tui-fixed-y{
width: 100%;
height: calc(100% - 80rpx);
position: fixed;
bottom: 0;
left: 0;
}
.tui-city-scroll-y{
padding: 0 20rpx;
height: 100%;
box-sizing: border-box;
}
.tui-list-head{
height: 50px;
line-height: 50px;
text-align: center;
font-size: 30rpx;
color: blue;
}
.tui-list-li{
height: 400px;
padding: 10rpx;
color: #fff;
font-size: 50rpx;
background-color: lightgreen;
}
JS
Page({
data: {
navList: ['今日特惠', '煙灶推薦', '凈水飲水推薦', '洗碗機(jī)推薦', '電熱推薦', '燃熱推薦', '消毒柜推薦', '嵌入式推薦', '商用電器','活動(dòng)說(shuō)明'],
status: 0
},
getStatus(e){
this.setData({ status: e.currentTarget.dataset.index})
}
})
注意
- scroll-view 組件如果橫向滾動(dòng)必須要有一個(gè)可視寬度,縱向滾動(dòng)必須要有一個(gè)可視高度;
- 滾動(dòng)的定位采用 scroll-view 組件的 scroll-into-view 屬性,用 id 進(jìn)行定位。
DEMO下載
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序 scroll-view實(shí)現(xiàn)錨點(diǎn)滑動(dòng)的示例
- 微信小程序上滑加載下拉刷新(onscrollLower)分批加載數(shù)據(jù)(二)
- 微信小程序-橫向滑動(dòng)scroll-view隱藏滾動(dòng)條
- 微信小程序scroll-view實(shí)現(xiàn)橫向滾動(dòng)和上拉加載示例
- 微信小程序 scroll-view實(shí)現(xiàn)上拉加載與下拉刷新的實(shí)例
- 微信小程序 scroll-view隱藏滾動(dòng)條詳解
- 微信小程序 scroll-view組件實(shí)現(xiàn)列表頁(yè)實(shí)例代碼
- 微信小程序 教程之wxapp視圖容器 scroll-view
- 微信小程序(九)scroll-view組件詳細(xì)介紹
- 微信小程序?qū)崿F(xiàn)YDUI的ScrollTab組件
相關(guān)文章
推薦一個(gè)封裝好的getElementsByClassName方法
這篇文章主要推薦一個(gè)封裝好的getElementsByClassName方法,需要的朋友可以參考下2014-12-12
javascript 星級(jí)評(píng)分效果(手寫)
今天上午抽空隨手寫了個(gè)星級(jí)評(píng)分的效果,給大家分享下。由于水平有限,如有問(wèn)題請(qǐng)指出;首先要準(zhǔn)備一張星星的圖片,灰色是默認(rèn)狀態(tài),黃色是選擇狀態(tài),需要的朋友可以參考下2012-12-12
用html+css+js實(shí)現(xiàn)的一個(gè)簡(jiǎn)單的圖片切換特效
這篇文章主要介紹了用html+css+js實(shí)現(xiàn)的一個(gè)簡(jiǎn)單的圖片切換特效,需要的朋友可以參考下2014-05-05
一些經(jīng)常會(huì)用到的Javascript檢測(cè)函數(shù)
一些經(jīng)常會(huì)用到的Javascript檢測(cè)函數(shù),都是在prototype上面的擴(kuò)展。2010-05-05
javascript實(shí)現(xiàn)簡(jiǎn)單滾動(dòng)窗口
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)簡(jiǎn)單滾動(dòng)窗口,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
JS二進(jìn)制流文件下載導(dǎo)出(接口返回二進(jìn)制流)亂碼處理方法
這篇文章主要介紹了JS二進(jìn)制流文件下載導(dǎo)出(接口返回二進(jìn)制流)亂碼處理方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-12-12

