通过 offsetTop 属性可以设置组件在吸顶时与顶部的距离。
<Sticky offsetTop={100}>
<Button color="primary">吸顶距离</Button>
</Sticky>通过 container 属性可以指定组件的容器,页面滚动时,组件会始终保持在容器范围内,当组件即将超出容器底部时,会固定在容器的底部。
function StickyWithContainer() {
const container = useRef()
return (
<View ref={container}>
<Sticky container={container}>
<Button color="warning">指定容器</Button>
</Sticky>
</View>
)
}将 position 设置为 bottom 可以让组件吸附在底部。通过 offsetBottom 属性可以设置组件在吸底时与底部的距离。
<Sticky position="bottom" offsetBottom={50}>
<Button color="primary">吸底距离</Button>
</Sticky>| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| position | 吸附位置,可选值为 bottom | string | top |
| offsetTop | 吸顶时与顶部的距离,支持 px vw vh rem 单位,默认 px | number | string | 0 |
| offsetBottom | 吸底时与底部的距离,支持 px vw vh rem 单位,默认 px | number | string | 0 |
| container | 容器对应的 HTML 节点 | Element | - |