メインコンテンツまでスキップ
Version: v6

ion-content

shadow

Contentコンポーネントは、スクロール可能領域を制御するいくつかの便利なメソッドを備えた、 使いやすいコンテンツ領域を提供します。 1つのビューに表示できるコンテンツは1つだけです。

Contentは、他の多くのIonicコンポーネントと同様に、 CSS Utilities で提供されるグローバルスタイルを使用するか、CSSおよび使用可能な CSS Custom Properties を使用して個別にスタイル設定することによって、paddingmargin などを変更するようにカスタマイズできます。

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

<<<<<<< HEAD

スクロール可能な領域の外側に要素を配置するために、要素に slot="fixed" を追加することができます。これは、要素を左上に絶対配置します。それ以外の場所に配置するには、top, right, bottom, left でスタイルを指定します。

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.

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.

Theming

Colors

CSS Shadow Parts

CSS Custom Properties

99d3f5222ffbfc340f268bf630572d37e9d9586b

Interfaces

ScrollBaseDetail

interface ScrollBaseDetail {
isScrolling: boolean;
}

ScrollDetail

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

ScrollBaseCustomEvent

必須ではありませんが、ionScrollStartionScrollEnd イベントをより強く型付けするために、CustomEvent インターフェースの代わりにこのインターフェースを利用することが可能です。

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

ScrollCustomEvent

必須ではありませんが、ionScroll イベントをより強く型付けするために、CustomEvent インターフェースの代わりにこのインターフェースを利用することが可能です。

interface ScrollCustomEvent extends ScrollBaseCustomEvent {
detail: ScrollDetail;
}

<<<<<<< HEAD

使い方

<ion-content
[scrollEvents]="true"
(ionScrollStart)="logScrollStart()"
(ionScroll)="logScrolling($event)"
(ionScrollEnd)="logScrollEnd()">
<h1>Main Content</h1>

<div slot="fixed">
<h1>Fixed Content</h1>
</div>
</ion-content>
<ion-content>
<h1>Main Content</h1>

<div slot="fixed">
<h1>Fixed Content</h1>
</div>
</ion-content>
var content = document.querySelector('ion-content');
content.scrollEvents = true;
content.addEventListener('ionScrollStart', () => console.log('scroll start'));
content.addEventListener('ionScroll', (ev) => console.log('scroll', ev.detail));
content.addEventListener('ionScrollEnd', () => console.log('scroll end'));
import React from 'react';
import { IonContent } from '@ionic/react';

const ContentExample: React.FC = () => (
<IonContent
scrollEvents={true}
onIonScrollStart={() => {}}
onIonScroll={() => {}}
onIonScrollEnd={() => {}}>
<h1>Main Content</h1>

<div slot="fixed">
<h1>Fixed Content</h1>
</div>
</IonContent>
);
import { Component, h } from '@stencil/core';

@Component({
tag: 'content-example',
styleUrl: 'content-example.css'
})
export class ContentExample {
logScrollStart() {
console.log('Scroll start');
}

logScrolling(ev) {
console.log('Scrolling', ev);
}

logScrollEnd() {
console.log('Scroll end');
}

render() {
return [
<ion-content
scrollEvents={true}
onIonScrollStart={() => this.logScrollStart()}
onIonScroll={(ev) => this.logScrolling(ev)}
onIonScrollEnd={() => this.logScrollEnd()}>
<h1>Main Content</h1>

<div slot="fixed">
<h1>Fixed Content</h1>
</div>
</ion-content>
];
}
}
<template>
<ion-content
:scroll-events="true"
@ionScrollStart="logScrollStart()"
@ionScroll="logScrolling($event)"
@ionScrollEnd="logScrollEnd()">
<h1>Main Content</h1>

<div slot="fixed">
<h1>Fixed Content</h1>
</div>
</ion-content>
</template>

<script>
import { IonContent } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
components: { IonContent }
});
</script>

プロパティ

=======

Properties

99d3f5222ffbfc340f268bf630572d37e9d9586b

color

DescriptionThe color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming.
Attributecolor
Type"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined
Defaultundefined

forceOverscroll

DescriptionIf true and the content does not cause an overflow scroll, the scroll interaction will cause a bounce. If the content exceeds the bounds of ionContent, nothing will change. Note, the does not disable the system bounce on iOS. That is an OS level setting.
Attributeforce-overscroll
Typeboolean | undefined
Defaultundefined

fullscreen

DescriptionIf true, the content will scroll behind the headers and footers. This effect can easily be seen by setting the toolbar to transparent.
Attributefullscreen
Typeboolean
Defaultfalse

scrollEvents

DescriptionBecause of performance reasons, ionScroll events are disabled by default, in order to enable them and start listening from (ionScroll), set this property to true.
Attributescroll-events
Typeboolean
Defaultfalse

scrollX

DescriptionIf you want to enable the content scrolling in the X axis, set this property to true.
Attributescroll-x
Typeboolean
Defaultfalse

scrollY

DescriptionIf you want to disable the content scrolling in the Y axis, set this property to false.
Attributescroll-y
Typeboolean
Defaulttrue

イベント

NameDescription
ionScrollEmitted while scrolling. This event is disabled by default. Set scrollEvents to true to enable.
ionScrollEndEmitted when the scroll has ended. This event is disabled by default. Set scrollEvents to true to enable.
ionScrollStartEmitted when the scroll has started. This event is disabled by default. Set scrollEvents to true to enable.

メソッド

getScrollElement

DescriptionGet the element where the actual scrolling takes place. This element can be used to subscribe to scroll events or manually modify scrollTop. However, it's recommended to use the API provided by ion-content:

i.e. Using ionScroll, ionScrollStart, ionScrollEnd for scrolling events and scrollToPoint() to scroll the content into a certain point.
SignaturegetScrollElement() => Promise<HTMLElement>

scrollByPoint

DescriptionScroll by a specified X/Y distance in the component.
SignaturescrollByPoint(x: number, y: number, duration: number) => Promise<void>

scrollToBottom

DescriptionScroll to the bottom of the component.
SignaturescrollToBottom(duration?: number) => Promise<void>

scrollToPoint

DescriptionScroll to a specified X/Y location in the component.
SignaturescrollToPoint(x: number | undefined | null, y: number | undefined | null, duration?: number) => Promise<void>

scrollToTop

DescriptionScroll to the top of the component.
SignaturescrollToTop(duration?: number) => Promise<void>

CSS Shadow Parts

NameDescription
backgroundThe background of the content.
scrollThe scrollable container of the content.

CSSカスタムプロパティ

NameDescription
--backgroundBackground of the content
--colorColor of the content
--keyboard-offsetKeyboard offset of the content
--offset-bottomOffset bottom of the content
--offset-topOffset top of the content
--padding-bottomBottom padding of the content
--padding-endRight padding if direction is left-to-right, and left padding if direction is right-to-left of the content
--padding-startLeft padding if direction is left-to-right, and right padding if direction is right-to-left of the content
--padding-topTop padding of the content

Slots

NameDescription
``Content is placed in the scrollable area if provided without a slot.
fixedShould be used for fixed content that should not scroll.