微信小程序?qū)崿F(xiàn)YDUI的ScrollNav組件
更新時間:2018年02月02日 10:23:29 作者:Rattenking
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)YDUI的ScrollNav組件,滾動導航效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序?qū)崿F(xiàn)滾動導航效果的具體代碼,供大家參考,具體內(nèi)容如下
DEMO下載
效果圖

實現(xiàn)原理
采用雙 scroll-view 組件實現(xiàn)雙滾動!
WXML
<!--導航滾動 -->
<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>
<!--列表滾動區(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: ['今日特惠', '煙灶推薦', '凈水飲水推薦', '洗碗機推薦', '電熱推薦', '燃熱推薦', '消毒柜推薦', '嵌入式推薦', '商用電器','活動說明'],
status: 0
},
getStatus(e){
this.setData({ status: e.currentTarget.dataset.index})
}
})
注意
- scroll-view 組件如果橫向滾動必須要有一個可視寬度,縱向滾動必須要有一個可視高度;
- 滾動的定位采用 scroll-view 組件的 scroll-into-view 屬性,用 id 進行定位。
DEMO下載
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 微信小程序 scroll-view實現(xiàn)錨點滑動的示例
- 微信小程序上滑加載下拉刷新(onscrollLower)分批加載數(shù)據(jù)(二)
- 微信小程序-橫向滑動scroll-view隱藏滾動條
- 微信小程序scroll-view實現(xiàn)橫向滾動和上拉加載示例
- 微信小程序 scroll-view實現(xiàn)上拉加載與下拉刷新的實例
- 微信小程序 scroll-view隱藏滾動條詳解
- 微信小程序 scroll-view組件實現(xiàn)列表頁實例代碼
- 微信小程序 教程之wxapp視圖容器 scroll-view
- 微信小程序(九)scroll-view組件詳細介紹
- 微信小程序?qū)崿F(xiàn)YDUI的ScrollTab組件
相關文章
推薦一個封裝好的getElementsByClassName方法
這篇文章主要推薦一個封裝好的getElementsByClassName方法,需要的朋友可以參考下2014-12-12
用html+css+js實現(xiàn)的一個簡單的圖片切換特效
這篇文章主要介紹了用html+css+js實現(xiàn)的一個簡單的圖片切換特效,需要的朋友可以參考下2014-05-05
一些經(jīng)常會用到的Javascript檢測函數(shù)
一些經(jīng)常會用到的Javascript檢測函數(shù),都是在prototype上面的擴展。2010-05-05

