ion-content
Contentコンポーネントは、スクロール可能領域を制御するいくつかの便利なメソッドを備えた、 使いやすいコンテンツ領域を提供します。 1つのビューに表示できるコンテンツは1つだけです。
Contentは、他の多くのIonicコンポーネントと同様に、 padding や margin などを変更するようにカスタマイズできます。
Fixed Content
In order to place elements outside of the scrollable area,
slot="fixed" can be added to the element. This will absolutely position the element placing it in the top left. In order to place the element in a different position, style it using
top, right, bottom, and left.
利用方法
<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>
プロパティ
color | |
|---|---|
| Description | The color to use from your application's color palette.
Default options are: |
| Attribute | color |
| Type | string | undefined |
forceOverscroll | |
| Description | If |
| Attribute | force-overscroll |
| Type | boolean | undefined |
fullscreen | |
| Description | If |
| Attribute | fullscreen |
| Type | boolean |
| Default | false |
scrollEvents | |
| Description | Because of performance reasons, ionScroll events are disabled by default, in order to enable them
and start listening from (ionScroll), set this property to
|
| Attribute | scroll-events |
| Type | boolean |
| Default | false |
scrollX | |
| Description | If you want to enable the content scrolling in the X axis, set this property to |
| Attribute | scroll-x |
| Type | boolean |
| Default | false |
scrollY | |
| Description | If you want to disable the content scrolling in the Y axis, set this property to |
| Attribute | scroll-y |
| Type | boolean |
| Default | true |
イベント
| Name | Description |
|---|---|
ionScroll | Emitted while scrolling. This event is disabled by default. Look at the property: `scrollEvents` |
ionScrollEnd | Emitted when the scroll has ended. |
ionScrollStart | Emitted when the scroll has started. |
メソッド
getScrollElement | |
|---|---|
| Description | Get the element where the actual scrolling takes place.
This element can be used to subscribe to
i.e. Using |
| Signature | getScrollElement() => Promise<HTMLElement> |
scrollByPoint | |
| Description | Scroll by a specified X/Y distance in the component. |
| Signature | scrollByPoint(x: number, y: number, duration: number) => Promise<void> |
scrollToBottom | |
| Description | Scroll to the bottom of the component. |
| Signature | scrollToBottom(duration?: number) => Promise<void> |
scrollToPoint | |
| Description | Scroll to a specified X/Y location in the component. |
| Signature | scrollToPoint(x: number | undefined | null, y: number | undefined | null, duration?: number) => Promise<void> |
scrollToTop | |
| Description | Scroll to the top of the component. |
| Signature | scrollToTop(duration?: number) => Promise<void> |
CSS Shadow Parts
| Name | Description |
|---|---|
background | The background of the content. |
scroll | The scrollable container of the content. |
CSSカスタムプロパティ
| Name | Description |
|---|---|
--background | Background of the content |
--color | Color of the content |
--keyboard-offset | Keyboard offset of the content |
--offset-bottom | Offset bottom of the content |
--offset-top | Offset top of the content |
--padding-bottom | Bottom padding of the content |
--padding-end | Right padding if direction is left-to-right, and left padding if direction is right-to-left of the content |
--padding-start | Left padding if direction is left-to-right, and right padding if direction is right-to-left of the content |
--padding-top | Top padding of the content |
slot属性
| Name | Description |
|---|---|
| Content is placed in the scrollable area if provided without a slot. | |
"fixed" | Should be used for fixed content that should not scroll. |

