本文实例为大家分享了scroll-view组件实现索引列表滚动动画效果,供大家参考,具体内容如下
效果图
实现原理
利用scroll-view的scroll-into-view属性进行定位; 利用scroll-view的scroll-with-animation属性实现滚动动画过度。
WXML
<view class="city-layer {{isShowLayer ? '' : 'layer-hide'}}">
{{codeY}}
<view class="current-choose-city">当前选择机场:{{chooseCity}}
<scroll-view class="city-scroll" scroll-y="true" scroll-into-view="{{codeY}}" scroll-with-animation="true" style="height:{{cityHeight}}px" bindscroll="scroll">
<view class="city-Box" wx:for="{{cityList}}" wx:key="{{item.code}}">
<view class="city-code" id="{{item.code}}">{{item.code}}
<view class="city-list" wx:for="{{item.cityList}}" wx:for-item="city" bindtap="getChooseCity" data-city="{{city}}">
{{city}}
WXSS
<div class="jb51code">
<pre class="brush:css;">
.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,.7);
position: fixed;
top: calc(50% - 35px);
left:calc(50% - 35px);
z-index: 11;
}
.layer-hide{display: none;}