吸顶效果
1.结构部分
<view class="tab_box">
<view
:class="{ active: curIndex === index }"
@click="curBtn(index)"
v-for="(item, index) in ['tab1','tab2']"
:key="index"
>
<text>{{ item }}</text>
<view :class="{ active: curIndex === index }"></view>
</view>
</view>
css部分
.tab_box{
padding: 0 80rpx;
background: pink;
position: -webkit-sticky;
position: sticky;
top: -2rpx;//
height: 96rpx;
z-index: 999;
color: #666;
display: flex;
justify-content: space-between;
}
!!!注意以下几点
- 吸顶盒子的父元素不可有overflow:hidden或overflow:auto属性,否则失效
- 吸顶盒子的父元素不可是scroll-view
- 必须有left,right,top,bottom其中一个属性来确定位置