小程序scroll-view 实现瞄点
<scroll-view :style="{height:autoHeight}" :scroll-y="true" @scrolltolower="scrolltolower" @scroll="scroll" :scroll-into-view="toView" :scroll-with-animation="true" class="scroll-warp" :enable-back-to-top="true"> <div v-for="(item,index) in cityArr" :key="index"> <p class="title mb20" :id="item.initial">{{ item.initial }}</p> <div class="cityBox"> <!-- :style="{marginRight:(childrenIndex%3 === 2) ? 0 : '26rpx' }" --> <div v-for="(citys,childrenIndex) in item.chooseCitys" :key="childrenIndex"> <div class="rowFlexBox" :class="{ activeFlex:citys.length === 2 }"> <div v-for='(j,k) in citys' :key="k" :class="{ activeColor:activeIndex === childrenIndex && bgIndex === index && lastIndex === k }" class="cityStyle" @click="chooseCity(item,index,citys,childrenIndex,j,k)" >{{ j.short_name }}</div> </div> </div> </div> </div> </scroll-view>
默认是toView:'A',
// 选择的时候赋值上
// chooseLetter 是你点击的地方,
// toView 是你想要跳的地方
chooseLetter(item,index){
this.Tips(item);
if (item === 'A') {
this.toView = 'A' ;
} else {
this.toView = item ;
}
console.log(this.toView,'this.toView')
},
作者:人参,每篇随笔皆原创(除非注明原作者的随笔),欢迎指正!