微信小程式實現YDUI的ScrollNav組件,

來源:互聯網
上載者:User

小程式實現YDUI的ScrollNav組件,

本文執行個體為大家分享了小程式實現滾動導航效果的具體代碼,供大家參考,具體內容如下

DEMO下載

實現原理

採用雙 scroll-view 組件實現雙滾動!

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><!--列表滾動區 --><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下載

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.