在某些页面字母顺序排序是很常见的功能,当然在小程序中也不会例外,很多特效还没有成熟案例,只能原生重写,所以今天在分享个非常漂亮的字母顺序排序特效。今天我们就分享这样的小教程。希望对大家有所帮助。
不多说了,二当家要上图来啦!
快去拿个小板凳,坐等更多更新
注意:如若需要请联系微信geekxz
<view class="right-nav">
<view bindtap="getCurrentCode" class="{{chooseIndex == index ? '.city-list-active' : ''}}" wx:for="{{cityList}}" wx:key="" 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" scroll-top="{{scrollTop}}">
<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" wx:key="" data-city="{{city}}">
{{city}}
</view>
</view>
</scroll-view>
var city_list = require('./city.js');
Page({
data: {
cityList: city_list.city,
chooseCity: '您还未选择机场!',
isShowLayer: false,
chooseIndex: 0,
len: [],
code: null,
codeY: 'A',
codeHeight: null,
cityHeight:null,
scrollTop: 0
},
onLoad (options) {
var windowHeight = wx.getSystemInfoSync().windowHeight;
var arr = [];
this.data.cityList.forEach(current => arr.push(current.cityList.length + 1));
this.setData({
codeHeight: (windowHeight - 50) / this.data.cityList.length,
cityHeight: windowHeight - 50,
len: arr
});
},
getCurrentCode(e){
var index = e.target.dataset.index, sum = 0,self = this;
for (var j = 0; j < index; j++) {
sum += this.data.len[j];
}
this.setData({
codeY: e.target.dataset.code,
chooseIndex: e.target.dataset.index,
isShowLayer: true
})
// this.setData({
// code: e.target.dataset.code,
// scrollTop: sum * 40,
// chooseIndex: index,
// isShowLayer: true
// });
setTimeout(() => {
self.setData({ isShowLayer: false })
},500);
},
getChooseCity(e){
this.setData({ chooseCity: e.target.dataset.city });
}
})
获取city.js
文件数据请加 微信:geekxz
.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;}
注意路径问题
极客小寨:专注技术干货分享
围观
丨更多
热文
丨更多
热文
丨更多
热文
关于Geekxz的那些事儿
更多分享,请持续关注“极客小寨”
很多未公开的、隐藏的功能,用心去发现,惊喜总是会有的!
点击上方“编程微刊”,选择“置顶公众号”
第一时间关注web前端技术干货!
One More Thing...
编程微刊
公众号回复“1”,拉你进程序员技术讨论群。
公众号回复“小程序”,领取300个优秀的小程序开源代码。
公众号回复“视频”,领取180GJava视频学习资源。
公众号回复“书籍”,领取小编【前端小册】一本。
公众号回复“领取资源”,领取300G前端,Java,产品经理,微信小程序,Python等资源合集大放送。