scroll-x: x-axis scroll
scroll-into-view: id name immediately scroll to the current element area
<scroll-view scroll-x="true" class="scroll-content" :scroll-into-view='scrollIntoIndex'>
<view
:id="'top'+index"
v-for="(item,index) in topBar"
:key="index"
class="scroll-item"
@tap="changeTab(index)"
>
<!-- 根据index来判断样式是否选择 -->
<text :class="topBarIndex===index?'f-active-color':'f-color'">{{item.name}}</text>
</view>
</scroll-view>
data() {
return {
//选中的索引
topBarIndex:0,
//顶栏跟随的索引id值
scrollIntoIndex:"top0",
//中间内容块的高度
mainClientHeight:0,
//顶栏数据
topBar:[
],
//承载数据
newTopBar:[],
}
},