效果图:

wxml代码:

  <block wx:for="{{list}}">
<view class='letter' id="letter{{index}}">{{index}}</view>
<view class='item' wx:for="{{item}}" wx:for-item="idx">
{{idx.name}}
</view>
</block> <view class='letters'>
<text wx:for="{{list}}" bindtap='chooseLetter' data-letter="{{index}}">{{index}}</text>
</view>

WCSS代码:

.letter{ background: #ccc; font-size: 14px; padding-left: 10px;}
.item{ line-height: 40px; padding: 0 10px; border-bottom: 1px solid #eee;}
page{ width: 100%; height: 100%;}
scroll-view{ width: 100%; height: 100%;}
.letters{ position: fixed; top: 0px; right:; width: 30px; height: 100%; background: #eee;
display: flex; flex-flow: column;}
.letters text{ display: block; font-size: 14px; color: #666; text-align: center; flex:;}

js代码

onLoad: function (options) {
var that = this;
wx.request({
url: 'http://api.besttool.cn/?c=Car&a=brandlist',
method:'post',
header:{
'content-type': 'application/x-www-form-urlencoded'
},
data:{
appid:1,
secret:'d90824a5a8224fd7bb4fdffd331c62aa'
},
success(res){
console.log(res);
that.setData({ list: res.data.brandlist});
}
})
}, chooseLetter(e){
this.setData({
curLetter: null
});
var letter = e.currentTarget.dataset.letter;
console.log(letter); // 查找对应的id
var id = "#letter" + letter;
const query = wx.createSelectorQuery()
query.select(id).boundingClientRect()
query.selectViewport().scrollOffset()
query.exec(function (res) {
wx.pageScrollTo({
scrollTop: res[0].top + res[1].scrollTop,
duration: 300
})
})
},

点击右侧的字母会自动滚动到对应的位置。

微信小程序通讯录首字母索引效果,车辆品牌选择列表的更多相关文章

  1. 微信小程序通讯录字母排序

    微信小程序通讯录 字母排序效果: demo地址:https://github.com/PeachCoder/wechat-contacts

  2. 微信小程序实现标签页滑块效果

    微信小程序实现标签页滑块效果 小程序完整代码: wxml: <view class="swiper-tab"> <view class="swiper- ...

  3. 微信小程序里实现跑马灯效果

    在微信小程序 里实现跑马灯效果,类似滚动字幕或者滚动广告之类的,使用简单的CSS样式控制,没用到JS wxml: <!-- 复制的跑马灯效果 --> <view class=&quo ...

  4. 微信小程序实现“鲜肉APP”首页效果

    项目地址http://git.oschina.net/djcx/WeiXinXiaoChengXu/tree/master 如果您觉得不错,记得给一个star 由于微信小程序目前是当下趋势,正好昨天弄 ...

  5. 【微信小程序】手写索引选择器(城市列表,汽车品牌选择列表)

    摘要: 小程序索引选择器,点击跳转相应条目,索引可滑动,滑动也可跳转 场景:城市选择列表, 汽车品牌选择列表 所用组件: scroll-view(小程序原生) https://developers.w ...

  6. 微信小程序实现左滑删除效果(原生/uni-app)

    实现效果 列表中侧滑删除 删除不同时存在 scrollview上下滑动与侧滑删除不影响 uni-app实现 html部分 <template> <scroll-view :scrol ...

  7. 微信小程序——通讯录

    WXML: <view class="flex box box-lr"> <scroll-view class="flex groups box box ...

  8. 微信小程序播放视频发送弹幕效果

    首先.先来看一下效果图 然后.再看一下官方文档API对video的说明 相关属性解析: danmu-list:弹幕列表 enable-danmu:是否显示弹幕 danmu-btn:弹幕按钮 contr ...

  9. 微信小程序全选多选效果

    效果图: 代码: wxml <view class='hei_top'> <view class='hei_p'>共 <text>4</text> 场& ...

随机推荐

  1. php中require_once与include_once的区别

    首先include_once仅包含文件一次,如果没有文件,会发出警告,并继续执行. 而require_once也是仅包含文件一次,但是如果程序中没有找到文件,则程序会中止执行.

  2. 6-1 Deque(25 分)Data Structures and Algorithms (English)

    A "deque" is a data structure consisting of a list of items, on which the following operat ...

  3. POI2013题解

    POI2013题解 只做了BZ上有的\(13\)道题. 就这样还扔了两道神仙构造和一道计算几何题.所以只剩下十道题了. [BZOJ3414][Poi2013]Inspector 肯定是先二分答案,然后 ...

  4. swagger api 转graphql npm 包试用

    graphql 比较方便的进行api 的查询,操作,swagger 是一个方便的open api 描述标准,当前我们有比较多的 restapi 但是转换为graphql 是有成本的,还好swagger ...

  5. std::function与std::bind 函数指针

    function模板类和bind模板函数,使用它们可以实现类似函数指针的功能,但却却比函数指针更加灵活,特别是函数指向类 的非静态成员函数时. std::function可以绑定到全局函数/类静态成员 ...

  6. java内存上堆和栈的一些理解

    多线程上的基本类型:https://blog.csdn.net/championhengyi/article/details/76857401

  7. zipkin对于dubbo的支持

    对于Web端: 1. 需要在applicationContext的头部添加中添加prefix引用: xmlns:dubbo="http://code.alibabatech.com/sche ...

  8. windows默认文件浏览器大小

    windows打开之后,发现默认窗口很小.

  9. 锐捷 rg-S2026f 学习笔记

    1.通过串口连接交换机: http://support.ruijie.com.cn/forum.php?mod=viewthread&tid=32250&extra=page%3D1& ...

  10. 峰Spring4学习(8)spring对事务的支持

    一.事务简介: 二.编程式事务管理: 例子 1.需求:模拟转账,张三向李四转账50元: 数据库中存在t_count表: 代码实现: BankDao.java: package com.cy.dao; ...