PHP前端开发

微信小程序开发之好友列表字母列表跳转对应位置

百变鹏仔 5天前 #前端问答
文章标签 跳转

这篇文章主要介绍了微信小程序开发之好友列表字母列表跳转对应位置的相关资料,希望通过本文能帮助到大家让大家实现这样的功能,需要的朋友可以参考下

微信小程序开发之好友列表字母列表跳转对应位置

前言:

在小程序里实现微信好友列表点击右侧字母列表跳转对应位置效果。写了个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 <p></p><p>样式部分 <br></p><p>index.wxss</p><p class="jb51code"></p><pre class="brush:js;toolbar:false;">/**index.wxss**/text { font-weight: bold}.letter { font-size: 12px; width: 24px; height: 100%; position: fixed; right: 0; top: 0; z-index: +999;}.litem { width: 24px; height: 18px; line-height: 18px; text-align: center;}.info { font-size: 12px; text-align: justify; overflow: hidden;}.active { background: rgba(0, 0, 0, 0.2);}.iitem { padding: 10rpx 10rpx; margin-bottom: 10rpx; border-radius: 8rpx; background: rgba(222,222,222,0.2); box-sizing: border-box;}.tips { width: 40px; height: 40px; background: rgba(0,0,0,0.4); font-size: 20px; text-align: center; line-height: 40px; color: #fff; position: fixed; left: 50%; top: 50%; margin: -20px; z-index: +999; border-radius: 10rpx;