::: sourceCode ## sticky-header > issues: https://issues.dcloud.net.cn/?mid=component.view-container.sticky.sticky-header > 源码: https://github.com/dcloudio/uni-app/tree/uni-app-x-alpha/src/uni_modules/uni-list-view/components/sticky-header ::: > 组件类型:UniStickyHeaderElement 吸顶布局容器

注意:暂时仅支持作为list-view、sticky-section的子节点, sticky-header不支持css样式!当一个容器视图设置多个sticky-header时,后一个sticky-header会停靠在前一个sticky-header的末尾处。 ### 兼容性 ### 属性 | 名称 | 类型 | 默认值 | 兼容性 | 描述 | | :- | :- | :- | :-: | :- | | padding | Array\ | \[0,0,0,0\] | Web: 4.02; 微信小程序: x; 支付宝小程序: x; Android(VDOM): 3.98; Android(Vapor): x; iOS(VDOM): 4.11; iOS(Vapor): x; HarmonyOS: x | 长度为 4 的数组,按 top、right、bottom、left 顺序指定内边距 | | offset-top | number | | 微信小程序: x; 支付宝小程序: x | *(number)*
吸顶时与顶部的距(px) | ### 使用场景 父元素滚动过程中,实现某个子元素固定到父元素顶部的需求 需求其实就是元素吸顶。可将需要吸顶元素放入sticky-header组件中,sticky-header组件作为父元素的子元素,放到吸顶元素原来的位置即可。 **示例:** ```html 向上滑动页面,体验sticky-header吸顶效果。 itme-content-{{index}} ``` #### 蒸汽模式注意事项 + 不支持padding属性,可以使用样式设置padding + sticky-header必须是sticky-section内首个元素 + 每个sticky-section下仅支持一个sticky-header #### VDOM模式注意事项 + 同一元素下不能存在多 `sticky-header` 组件,使用多个 `sticky-header` 组件需分别放到 `sticky-section` 中 + `sticky-header` 组件,不支持设置css样式,不要通过 class 和 style 设置样式 + 鸿蒙平台暂不支持 `padding` 属性,可通过设置子元素样式来实现类似效果 + 鸿蒙平台 `sticky-header` 组件只能作为 `sticky-section` 的子元素使用 + 鸿蒙平台API版本低于17的设备不支持 `sticky-header` 组件,可在滚动容器里自行监听滚动,设置某个区域的top为固定值来实现吸顶效果,参考hello uni-app x的模板->[scroll-view自定义滚动吸顶示例](https://gitcode.com/dcloud/hello-uni-app-x/blob/alpha/pages/template/scroll-view-sticky-section/scroll-view-sticky-section.uvue) ### 子组件 @children-tags 支持所有组件 ### 示例 示例为[hello uni-app x alpha分支](https://gitcode.com/dcloud/hello-uni-app-x/blob/prod_alpha/pages/component/sticky-header/sticky-header.uvue),与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例[另见](https://gitcode.com/dcloud/hello-uni-app-x/blob/master//pages/component/sticky-header/sticky-header.uvue) ::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/component/sticky-header/sticky-header > appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/component/sticky-header/sticky-header >示例 ```vue ``` :::