小程序中scroll-view组件实现效果之--------城市列表页的索引(scroll-into-view)

想要实现的功能是在一个城市列表页实现字母索引
在这里插入图片描述
点击字母跳转到相应的位置,在小程序里面利用scroll-view特别简单

首先需要索引字母添加一个点击事件,捕获到点击的id

  <view wx:for ="{
  
  {searchLetter}}" wx:key="index" data-letter="{
  
  {item.name}}" catchtouchend="clickLetter">{
  
  {item.name}}</view>

然后给每个字母那行加上一个id="{ {outeritem.initial}}",每次点击索引字母,把捕获到的data-letter="{ { item.name}}" 的值赋值给scroll-into-view="{ {scrollTopId}}" 中的scrollTopId,那么就会自动跳转到和scrollTopId相同的id那块区域

 <scroll-view scroll-y="true" style="height:{
  
  {winHeight}}px" bindscroll="bindScroll" scroll-into-view="{
  
  {scrollTopId}}" scroll-top="{
  
  {scrollTop}}">
 	 <view  wx:for="{
  
  {CityList}}" wx:key="{
  
  {item.initial}}" wx:for-item="outeritem">
            <vi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值