/*! For license information please see 8507.3bc5d2dd.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["8507"],{74434:function(s,n,a){"use strict";a.r(n);var t=a("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'
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.
Register component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Sticky } from 'vant';\n\nconst app = createApp();\napp.use(Sticky);\n
\n<van-sticky>\n <van-button type="primary">Basic Usage</van-button>\n</van-sticky>\n
\n<van-sticky :offset-top="50">\n <van-button type="primary">Offset Top</van-button>\n</van-sticky>\n
\n<div ref="container" style="height: 150px;">\n <van-sticky :container="container">\n <van-button type="warning">Set Container</van-button>\n </van-sticky>\n</div>\n
\nexport default {\n setup() {\n const container = ref(null);\n return { container };\n },\n};\n
\n<van-sticky :offset-bottom="50" position="bottom">\n <van-button type="primary">Offset Bottom</van-button>\n</van-sticky>\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
position | \nOffset position, can be set to bottom | \nstring | \ntop | \n
offset-top | \nOffset top, supports px vw vh rem unit, default px | \nnumber | string | \n0 | \n
offset-bottom | \nOffset bottom, supports px vw vh rem unit, default px | \nnumber | string | \n0 | \n
z-index | \nz-index when sticky | \nnumber | string | \n99 | \n
container | \nContainer DOM | \nElement | \n- | \n
Event | \nDescription | \nArguments | \n
---|---|---|
change | \nEmitted when sticky status changed | \nisFixed: boolean | \n
scroll | \nEmitted when scrolling | \n{ scrollTop: number, isFixed: boolean } | \n
The component exports the following type definitions:
\nimport type { StickyProps, StickyPosition } from 'vant';\n
\nThe component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
\nName | \nDefault Value | \nDescription | \n
---|---|---|
--van-sticky-z-index | \n99 | \n- | \n