import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=n(`

Sticky

Intro

The sticky component is consistent with the effect achieved by the position: sticky property in CSS, in that when the component is within screen range, it will follow the normal layout arrangement, and when the component rolls out of screen range, it will always be fixed at the top of the screen.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { Sticky } from 'vant';

const app = createApp();
app.use(Sticky);

Usage

Basic Usage

<van-sticky>
  <van-button type="primary">Basic Usage</van-button>
</van-sticky>

Offset Top

<van-sticky :offset-top="50">
  <van-button type="primary">Offset Top</van-button>
</van-sticky>

Set Container

<div ref="container" style="height: 150px;">
  <van-sticky :container="container">
    <van-button type="warning">Set Container</van-button>
  </van-sticky>
</div>
export default {
  setup() {
    const container = ref(null);
    return { container };
  },
};

Offset Bottom

<van-sticky :offset-bottom="50" position="bottom">
  <van-button type="primary">Offset Bottom</van-button>
</van-sticky>

API

Props

AttributeDescriptionTypeDefault
position v3.0.6Offset position, can be set to bottomstringtop
offset-topOffset top, supports px vw vh rem unit, default pxnumber | string0
offset-bottom v3.0.6Offset bottom, supports px vw vh rem unit, default pxnumber | string0
z-indexz-index when stickynumber | string99
containerContainer DOMElement-

Events

EventDescriptionArguments
change v3.0.10Emitted when sticky status changedisFixed: boolean
scrollEmitted when scrolling{ scrollTop: number, isFixed: boolean }

Types

The component exports the following type definitions:

import type { StickyProps, StickyPosition } from 'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-sticky-z-index99-
`,14),p=[l],h={__name:"README",setup(o,{expose:s}){return s({frontmatter:{}}),(d,i)=>(a(),t("div",e,p))}};export{h as default};