这篇文章主要为大家详细介绍了微信小程序scroll-view组件实现滚动动画,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了scroll-view组件实现索引列表滚动动画效果,供大家参考,具体内容如下
实现原理
利用scroll-view的scroll-into-view属性进行定位;
利用scroll-view的scroll-with-animation属性实现滚动动画过度。
WXML
{{item.code}} {{codeY}} 当前选择机场:{{chooseCity}} {{item.code}} {{city}}
WXSS
.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;}JS
var city_list = require('./city.js');
Page({
data: {
cityList: city_list.city,
chooseCity: '您还未选择机场!',
isShowLayer: false,
chooseIndex: 0,
codeY: 'A',
codeHeight: null,
cityHeight:null
},
onLoad (options) {
var windowHeight = wx.getSystemInfoSync().windowHeight;
this.setData({
codeHeight: (windowHeight - 50) / this.data.cityList.length,
cityHeight: windowHeight - 50,
});
},
getCurrentCode(e){
var self = this;
this.setData({
codeY: e.target.dataset.code,
chooseIndex: e.target.dataset.index,
isShowLayer: true
})
setTimeout(() => {
self.setData({ isShowLayer: false })
},500);
},
getChooseCity(e){
this.setData({ chooseCity: e.target.dataset.city });
}
})对比
微信小程序—-全国机场索引列表(MUI索引列表)
对比结果总结
由于scroll-view的scroll-into-view属性是滚动到指定id位置,所以,在列表的字母行加上id属性;
多个微信小程序源码合集下载微信小程序是一种轻量级的应用开发平台,由腾讯公司推出,主要应用于移动端,旨在提供便捷的用户体验,无需下载安装即可在微信内使用。本压缩包包含了丰富的源码资源,涵盖了多个领域的应用场景,下面将逐一介绍其中涉及的知识点。1. 图片展示:这部分源码可能涉及了微信小程序中的``组件的使用,用于显示图片,以及`wx.getSystemInfo`接口获取屏幕尺寸,实现图片的适配和响应式布局。可能还包括了图片懒加
由于scroll-view的scroll-into-view属性实现了滚动到指定位置,所以减少了scrollTop的计算;
由于scroll-view的scroll-with-animation属性,实现了滚动动画过度效果;
减少了计算scrollTop的循环消耗;
js代码量减少,减少this.setData方法的变量设置。
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:










