Skip to main content

ion-header

页眉是页面的根组件,它与页面顶部对齐。建议用作一个或多个 toolbars 的封装器,但它可以用于封装任何元素。当在标题内部使用工具栏时,将调整内容以使其大小正确,并且标题将考虑任何设备安全区域。

¥Header is a root component of a page that aligns itself to the top of the page. It is recommended to be used as a wrapper for one or more toolbars, but it can be used to wrap any element. When a toolbar is used inside of a header, the content will be adjusted so it is sized correctly, and the header will account for any device safe areas.

基本用法

¥Basic Usage

半透明标头

¥Translucent Header

通过设置 translucent 属性,标头可以匹配原生 iOS 应用中的透明度。为了看到标题后面滚动的内容,需要在内容上设置 fullscreen 属性。仅当模式为 "ios" 并且设备支持 backdrop-filter 时,此效果才会生效。

¥Headers can match the transparency found in native iOS applications by setting the translucent property. In order to see the content scrolling behind the header, the fullscreen property needs to be set on the content. This effect will only apply when the mode is "ios" and the device supports backdrop-filter.

压缩标题

¥Condensed Header

Ionic 提供了原生 iOS 应用中的功能,可以显示大的工具栏标题,然后在滚动时将其折叠为小标题。这可以通过添加两个标头(一个在内容上方,一个在内容内部)来完成,然后将内容内部标头的 collapse 属性设置为 "condense"。该效果仅在模式为 "ios" 时有效。

¥Ionic provides the functionality found in native iOS applications to show a large toolbar title and then collapse it to a small title when scrolling. This can be done by adding two headers, one above the content and one inside of the content, and then setting the collapse property to "condense" on the header inside of the content. This effect will only apply when the mode is "ios".

淡入淡出标题

¥Fade Header

许多原生 iOS 应用的工具栏上都有淡入淡出效果。这可以通过将标头上的 collapse 属性设置为 "fade" 来实现。当页面首次加载时,标题上的背景和边框将被隐藏。当内容滚动时,标题将淡入。该效果仅在模式为 "ios" 时有效。

¥Many native iOS applications have a fade effect on the toolbar. This can be achieved by setting the collapse property on the header to "fade". When the page is first loaded, the background and border on the header will be hidden. As the content is scrolled, the header will fade back in. This effect will only apply when the mode is "ios".

此功能也可以与 压缩标题 结合使用。值设置为 "fade"collapse 属性应位于内容外部的标题上。

¥This functionality can be combined with a Condensed Header as well. The collapse property with a value set to "fade" should be on the header outside of the content.

与虚拟滚动一起使用

¥Usage with Virtual Scroll

淡入淡出标题需要滚动容器才能正常工作。使用虚拟滚动解决方案时,需要提供自定义滚动目标。需要禁用内容滚动,并且需要将 .ion-content-scroll-host 类添加到负责滚动的元素中。

¥A fade header requires a scroll container to work properly. When using a virtual scrolling solution, a custom scroll target needs to be provided. Scrolling on the content needs to be disabled and the .ion-content-scroll-host class needs to be added to the element responsible for scrolling.

边框

¥Borders

"md" 模式下,标头底部将有一个 box-shadow。在 "ios" 模式下,底部会显示 border。可以通过将 .ion-no-border 类添加到标头来删除它们。

¥In "md" mode, the header will have a box-shadow on the bottom. In "ios" mode, it will receive a border on the bottom. These can be removed by adding the .ion-no-border class to the header.

属性

¥Properties

collapse

DescriptionDescribes the scroll effect that will be applied to the header. Only applies in iOS mode.

Typically used for Collapsible Large Titles
Attributecollapse
Type"condense" | "fade" | undefined
Defaultundefined

mode

DescriptionThe mode determines which platform styles to use.
Attributemode
Type"ios" | "md"
Defaultundefined

translucent

DescriptionIf true, the header will be translucent. Only applies when the mode is "ios" and the device supports backdrop-filter.

Note: In order to scroll content behind the header, the fullscreen attribute needs to be set on the content.
Attributetranslucent
Typeboolean
Defaultfalse

事件

¥Events

No events available for this component.

方法

¥Methods

No public methods available for this component.

CSS 阴影部分

¥CSS Shadow Parts

No CSS shadow parts available for this component.

CSS 自定义属性

¥CSS Custom Properties

No CSS custom properties available for this component.

插槽

¥Slots

No slots available for this component.