Sticky 粘性布局

引入

app.jsonindex.json中引入组件,默认为ES6版本,ES5引入方式参见快速上手

"usingComponents": {
  "van-sticky": "path/to/vant-weapp/dist/sticky/index"
}

代码演示

基础用法

将内容包裹在Sticky组件内即可

<van-sticky>
  <van-button type="primary">基础用法</van-button>
</van-sticky>

吸顶距离

通过offset-top属性可以设置组件在吸顶时与顶部的距离

<van-sticky offset-top="{{ 30 }}">
  <van-button type="info">吸顶距离</van-button>
</van-sticky>

Props

参数 说明 类型 默认值
offset-top 吸顶时与顶部的距离,单位px number 0
z-index 吸顶时的 z-index number 99

Events

事件名 说明 回调参数
scroll 滚动时触发 { scrollTop: 距离顶部位置, isFixed: 是否吸顶 }