本文實(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)說明'], status: 0 }, getStatus(e){ this.setData({ status: e.currentTarget.dataset.index}) } })
注意
DEMO下載
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com