メインコンテンツまでスキップ
バージョン: v8

ion-content

shadow

The content component provides an easy to use content area with some useful methods to control the scrollable area. There should only be one content in a single view.

Content, along with many other Ionic components, can be customized to modify its padding, margin, and more using the global styles provided in the CSS Utilities or by individually styling it using CSS and the available CSS Custom Properties.

Basic Usage

Content can be the only top-level component in a page, or it can be used alongside a header, footer, or both. When used with a header or footer, it will adjust its size to fill the remaining height.

Fullscreen Content

By default, content fills the space between a header and footer but does not go behind them. In certain cases, it may be desired to have the content scroll behind the header and footer, such as when the translucent property is set on either of them, or opacity is set on the toolbar. This can be achieved by setting the fullscreen property on the content to true.

Fixed Content

To place elements outside of the scrollable area, assign them to the fixed slot. Doing so will absolutely position the element to the top left of the content. In order to change the position of the element, it can be styled using the top, right, bottom, and left CSS properties.

The fixedSlotPlacement property is used to determine if content in the fixed slot is placed before or after the main content in the DOM. When set to before, fixed slot content will be placed before the main content and will therefore receive keyboard focus before the main content receives keyboard focus. This can be useful when the main content contains an infinitely-scrolling list, preventing a FAB or other fixed content from being reachable by pressing the tab key.

Scroll Methods

Content provides methods that can be called to scroll the content to the bottom, top, or to a specific point. They can be passed a duration in order to smoothly transition instead of instantly changing the position.

Scroll Events

Scroll events are disabled by default for content due to performance. However, they can be enabled by setting scrollEvents to true. This is necessary before listening to any of the scroll events.

Console
Console messages will appear here when logged from the example above.

Theming

Colors

CSS Shadow Parts

CSS Custom Properties

Safe Area Padding

The content component will not automatically apply padding to any of its sides to account for the safe area. This is because the content component is often used in conjunction with other components that apply their own padding, such as headers and footers. However, if the content component is being used on its own, it may be desired to apply padding to the safe area. This can be done through CSS by using the --ion-safe-area-(dir) variables described in Application Variables.

The most common use case for this is to apply padding to the top of the content to account for the status bar. This can be done by setting the padding-top property to the value of the --ion-safe-area-top variable.

ion-content::part(scroll) {
padding-top: var(--ion-safe-area-top, 0);
}

Another common use case is to apply padding to the left side of the content to account for the notch when the device is in landscape mode and the notch is on the left side. This can be done by setting the padding-left property to the value of the --ion-safe-area-left variable.

ion-content::part(scroll) {
padding-left: var(--ion-safe-area-left, 0);
}

Interfaces

ScrollBaseDetail

interface ScrollBaseDetail {
isScrolling: boolean;
}

ScrollDetail

interface ScrollDetail extends GestureDetail, ScrollBaseDetail {
scrollTop: number;
scrollLeft: number;
}

ScrollBaseCustomEvent

While not required, this interface can be used in place of the CustomEvent interface for stronger typing on the ionScrollStart and ionScrollEnd events.

interface ScrollBaseCustomEvent extends CustomEvent {
detail: ScrollBaseDetail;
target: HTMLIonContentElement;
}

ScrollCustomEvent

While not required, this interface can be used in place of the CustomEvent interface for stronger typing on the ionScroll event.

interface ScrollCustomEvent extends ScrollBaseCustomEvent {
detail: ScrollDetail;
}

Properties

color

Descriptionアプリケーションのカラーパレットから使用する色を指定します。デフォルトのオプションは以下の通りです。 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", と "dark" です.色に関する詳しい情報は theming を参照してください。
Attributecolor
Type"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined
Defaultundefined

fixedSlotPlacement

Description固定コンテンツが DOM 内のメイン・コンテンツの相対的などこに配置されるかを制御します。これは、固定要素がキーボード・フォーカスを受ける順番を制御するために使用できます。例えば、固定スロットのFABがメインページのコンテンツよりも先にキーボードフォーカスを受け取るようにする場合、このプロパティを 'before' に設定します。
Attributefixed-slot-placement
Type"after" | "before"
Default'after'

forceOverscroll

Descriptiontrueで、コンテンツがオーバーフロースクロールを引き起こさない場合、スクロールインタラクションはバウンスを引き起こします。コンテンツがionContentの境界を超えた場合、何も変化しません。なお、これはiOSのシステムバウンスを無効にするものではありません。これはOSレベルの設定です。
Attributeforce-overscroll
Typeboolean | undefined
Defaultundefined

fullscreen

Descriptiontrueの場合、コンテンツはヘッダーとフッターの後ろにスクロールされます。この効果は、ツールバーを透明に設定することで簡単に確認することができます。
Attributefullscreen
Typeboolean
Defaultfalse

scrollEvents

Descriptionパフォーマンス上の理由から、ionScrollイベントはデフォルトで無効になっています。ionScrollイベントを有効にして(ionScroll)からリスニングを開始するには、このプロパティをtrueに設定します。
Attributescroll-events
Typeboolean
Defaultfalse

scrollX

DescriptionX軸方向のコンテンツスクロールを有効にしたい場合は、このプロパティをtrueに設定します。
Attributescroll-x
Typeboolean
Defaultfalse

scrollY

DescriptionY軸方向のコンテンツスクロールを無効にしたい場合は、このプロパティにfalseを設定します。
Attributescroll-y
Typeboolean
Defaulttrue

Events

NameDescriptionBubbles
ionScrollスクロール中に発行されます。このイベントはデフォルトで無効になっています。有効にするには scrollEventstrue を設定します。true
ionScrollEndスクロールが終了したときに発行されます。このイベントはデフォルトで無効になっている。有効にするには scrollEventstrue を設定します。true
ionScrollStartスクロールが開始されたときに発行されます。このイベントはデフォルトで無効になっている。有効にするには scrollEventstrue を設定してください。true

Methods

getScrollElement

Description実際のスクロールが行われる要素を取得します。この要素を使用して、scroll イベントを購読したり、scrollTop を手動で変更したりすることができる。スクロールイベントには ionScroll, ionScrollStart, ionScrollEnd を、コンテンツを特定のポイントにスクロールさせるには scrollToPoint() を使用することが推奨されます。
SignaturegetScrollElement() => Promise<HTMLElement>

scrollByPoint

Descriptionコンポーネントを指定したX/Y距離だけスクロールさせる。
SignaturescrollByPoint(x: number, y: number, duration: number) => Promise<void>
Parametersx: The amount to scroll by on the horizontal axis.
y: The amount to scroll by on the vertical axis.
duration: The amount of time to take scrolling by that amount.

scrollToBottom

Descriptionコンポーネントの一番下までスクロールします。
SignaturescrollToBottom(duration?: number) => Promise<void>
Parametersduration: The amount of time to take scrolling to the bottom. Defaults to 0.

scrollToPoint

Descriptionコンポーネント内の指定したX/Y位置までスクロールします。
SignaturescrollToPoint(x: number | undefined | null, y: number | undefined | null, duration?: number) => Promise<void>
Parametersx: The point to scroll to on the horizontal axis.
y: The point to scroll to on the vertical axis.
duration: The amount of time to take scrolling to that point. Defaults to 0.

scrollToTop

Descriptionコンポーネントの上部にスクロールします。
SignaturescrollToTop(duration?: number) => Promise<void>
Parametersduration: The amount of time to take scrolling to the top. Defaults to 0.

CSS Shadow Parts

NameDescription
backgroundコンテンツの背景です。
scrollコンテンツのスクロール可能なコンテナ。

CSS Custom Properties

NameDescription
--backgroundコンテンツの背景
--colorコンテンツの色
--keyboard-offsetコンテンツのキーボードオフセット
--offset-bottomコンテンツのオフセットボトム
--offset-topコンテンツのオフセットトップ
--padding-bottomコンテンツのBottom Padding
--padding-endコンテンツの方向が左から右の場合はRight Padding、右から左の場合はLeft Paddingとなります。
--padding-startコンテンツの方向が左から右の場合はLeft Padding、右から左の場合はRight Paddingとなります。
--padding-topコンテンツのTop Padding

Slots

NameDescription
``slotなしで提供される場合、コンテンツはスクロール可能な領域に配置されます。
fixedスクロールしてはいけない固定コンテンツに使用する必要があります。