国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

微信小程序scroll-view組件實現滾動動畫

2024-05-06 16:42:12
字體:
來源:轉載
供稿:網友

本文實例為大家分享了scroll-view組件實現索引列表滾動動畫效果,供大家參考,具體內容如下

效果圖

 

實現原理

利用scroll-view的scroll-into-view屬性進行定位;
利用scroll-view的scroll-with-animation屬性實現滾動動畫過度。

WXML

<view class="right-nav">  <view bindtap="getCurrentCode" class="{{chooseIndex == index ? '.city-list-active' : ''}}" wx:for="{{cityList}}" style="height:{{codeHeight}}px" data-code="{{item.code}}" data-index="{{index}}">  {{item.code}}  </view></view><view class="city-layer {{isShowLayer ? '' : 'layer-hide'}}"> {{codeY}}</view><view class="current-choose-city">當前選擇機場:{{chooseCity}}</view><scroll-view class="city-scroll" scroll-y="true" scroll-into-view="{{codeY}}" scroll-with-animation="true" style="height:{{cityHeight}}px" bindscroll="scroll">  <view class="city-box" wx:for="{{cityList}}" wx:key="{{item.code}}">    <view class="city-code" id="{{item.code}}">{{item.code}}</view>    <view class="city-list" wx:for="{{item.cityList}}" wx:for-item="city" bindtap="getChooseCity" data-city="{{city}}">        {{city}}     </view>   </view></scroll-view>

WXSS

 

.current-choose-city{ position: fixed; width: 100%; height: 50px; line-height: 50px; padding: 0 10px; top: 0; left: 0; background-color: #fff; z-index: 10;}.right-nav{ width: 30px; color: #888; text-align: center; position: fixed; bottom: 0; right: 0; background-color: rgb(200, 200, 200); z-index: 9;}.city-scroll{padding-top: 50px;}.city-code{ background-color: #f7f7f7;}.city-list,.city-code{ height: 39px; line-height: 40px; padding: 0 30px 0 10px; overflow: hidden; border-bottom: 1px solid #c8c7cc;}.city-list-active{color:#007aff;}/*提示點擊的字母 */.city-layer{ width: 70px; height: 70px; line-height: 70px; text-align: center; border-radius: 50%; color: #fff; background-color: rgba(0, 0, 0, .7); position: fixed; top: calc(50% - 35px); left:calc(50% - 35px); z-index: 11;}.layer-hide{display: none;}

JS

var city_list = require('./city.js');Page({ data: {  cityList: city_list.city,  chooseCity: '您還未選擇機場!',  isShowLayer: false,  chooseIndex: 0,  codeY: 'A',  codeHeight: null,  cityHeight:null }, onLoad (options) {  var windowHeight = wx.getSystemInfoSync().windowHeight;  this.setData({    codeHeight: (windowHeight - 50) / this.data.cityList.length,   cityHeight: windowHeight - 50,  }); }, getCurrentCode(e){  var self = this;  this.setData({    codeY: e.target.dataset.code,   chooseIndex: e.target.dataset.index,   isShowLayer: true   })  setTimeout(() => {   self.setData({ isShowLayer: false })  },500); }, getChooseCity(e){  this.setData({ chooseCity: e.target.dataset.city }); }})

對比結果總結

  • 由于scroll-view的scroll-into-view屬性是滾動到指定id位置,所以,在列表的字母行加上id屬性;
  • 由于scroll-view的scroll-into-view屬性實現了滾動到指定位置,所以減少了scrollTop的計算;
  • 由于scroll-view的scroll-with-animation屬性,實現了滾動動畫過度效果;
  • 減少了計算scrollTop的循環消耗;
  • js代碼量減少,減少this.setData方法的變量設置。

DEMO下載

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 政和县| 霍州市| 高陵县| 容城县| 怀来县| 吉安县| 民丰县| 富源县| 苍山县| 宁明县| 南溪县| 永仁县| 通江县| 玉环县| 股票| 龙里县| 察隅县| 天峨县| 怀远县| 荃湾区| 长顺县| 铁岭县| 上林县| 龙游县| 西吉县| 庆安县| 南丰县| 贵定县| 泾川县| 志丹县| 读书| 盐津县| 巴青县| 株洲市| 灌云县| 安平县| 平利县| 梁山县| 衡山县| 东莞市| 东莞市|