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

首頁 > 熱點 > 微信 > 正文

微信小程序開發之好友列表字母列表跳轉對應位置

2024-07-22 01:17:20
字體:
來源:轉載
供稿:網友

微信小程序開發之好友列表字母列表跳轉對應位置

前言:

在小程序里實現微信好友列表點擊右側字母列表跳轉對應位置效果。寫了個demo,核心部分很簡單,所以沒多少注釋,如果遇到問題就加群問我吧。

核心技術點:

1、小程序scroll-view組件的scroll-into-view, scroll-with-animation. scroll-y屬性。
2、小程序的touch事件的應用。
3、Js定時器的應用。

view頁面代碼:

index.wxml

 class="container" scroll-y>  class="info" id="info" scroll-with-animation scroll-y scroll-top="200" scroll-into-view="{{toView}}" style="height:{{height}}px;">   class="iitem" id="{{item.id}}" wx:for="{{info_list}}" wx:key="1">   {{item.id}} . {{item.desc}}     class="letter {{active == true ? 'active': ''}}" bindtouchstart='start' bindtouchmove='move' bindtouchend='end'>   class="litem" bindtap='down' data-index="999">☆   class="litem" wx:for="{{letter_list}}" bindtap='down' wx:for-index="index" wx:key="2" data-index="{{index}}" style="height: {{letter_height}}px;">{{item}}  class="tips" hidden="{{hide}}">{{curView}}

js代碼:

index.js

//index.js//獲取應用實例const app = getApp()Page({ data: {  letter_list: [],  info_list: [],  hide: true,  active: false,  toView: 'A',  curView: 'A',  letter_height: 18 }, onLoad: function () {  this.active = false;  this.timer = null;  var letter_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];  var info_list = [];  for (var i = 0; i < 26; i++) {   var obj = {};   obj.id = letter_list;   obj.desc = '這是一個用于測試的DEMO。1.目標是用于實現微信好友列表的點擊首字母跳轉到對應好友位置。2.目標是用于實現微信好友列表的點擊首字母跳轉到對應好友位置';   info_list.push(obj);  }  this.setData({   height: app.globalData.height,   info_list: info_list,   letter_list: letter_list,   sHeight: 100 * 26 + 25  }); }, start: function (e) {  this.setData({   active: true,   hide: false  }) }, end: function (e) {  if (this.timer) {   clearTimeout(this.timer);   this.timer = null;  }  var moveY = e.changedTouches["0"].clientY - 18, that = this;  var curIndex = parseInt(moveY / 18);  var view = this.data.letter_list[curIndex];  this.setData({   toView: view,   active: false  });  if (!this.timer) {   this.timer = setTimeout(function () {    that.setData({     hide: true    })    that.timer = null;   }, 1000);  } }, move: function (e) {  var moveY = e.changedTouches["0"].clientY - 18;  var curIndex = parseInt(moveY / 18);  var view = this.data.letter_list[curIndex];  this.setData({   curView: view  }) }, down: function (e) {  if (this.timer) {   clearTimeout(this.timer);   this.timer = null;  }  var index = e.currentTarget.dataset.index,   that = this;  if (index != 999) {   var view = this.data.letter_list[index];   this.setData({    toView: view,    curView: view   })  } else {   this.setData({    toView: 'A',    curView: '☆'   })  }  if (!this.timer) {   this.timer = setTimeout(function () {    that.setData({     hide: true    });    that.timer = null;   }, 1000);  } }})            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淮南市| 乳源| 绥宁县| 富平县| 伽师县| 禄丰县| 天长市| 巴林左旗| 百色市| 汉阴县| 运城市| 中山市| 聂拉木县| 东乌珠穆沁旗| 庄河市| 正镶白旗| 峨边| 永丰县| 永靖县| 鹤岗市| 名山县| 大安市| 武山县| 喀什市| 恩施市| 和平区| 尉犁县| 大渡口区| 商水县| 宁安市| 磴口县| 合肥市| 镇康县| 高邑县| 衡山县| 津南区| 荔浦县| 绥德县| 思南县| 桃江县| 昌平区|