ion-content
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.
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.
Usage
- Angular
- Javascript
- React
- Stencil
- Vue
<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
color
Description | The 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. |
Attribute | color |
Type | string | undefined |
Default | undefined |
forceOverscroll
Description | If 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. |
Attribute | force-overscroll |
Type | boolean | undefined |
Default | undefined |
fullscreen
Description | If true , the content will scroll behind the headers and footers. This effect can easily be seen by setting the toolbar to transparent. |
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 true . |
Attribute | scroll-events |
Type | boolean |
Default | false |
scrollX
Description | X軸方向のコンテンツスクロールを有効にしたい場合は、このプロパティをtrue に設定します。 |
Attribute | scroll-x |
Type | boolean |
Default | false |
scrollY
Description | Y軸方向のコンテンツスクロールを無効にしたい場合は、このプロパティにfalse を設定します。 |
Attribute | scroll-y |
Type | boolean |
Default | true |
Events
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. |
Methods
getScrollElement
Description | Get 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. |
Signature | getScrollElement() => Promise<HTMLElement> |
scrollByPoint
Description | コンポーネントを指定したX/Y距離だけスクロールさせる。 |
Signature | scrollByPoint(x: number, y: number, duration: number) => Promise<void> |
scrollToBottom
Description | コンポーネントの一番下までスクロールします。 |
Signature | scrollToBottom(duration?: number) => Promise<void> |
scrollToPoint
Description | コンポーネント内の指定したX/Y位置までスクロールします。 |
Signature | scrollToPoint(x: number | undefined | null, y: number | undefined | null, duration?: number) => Promise<void> |
scrollToTop
Description | コンポーネントの上部にスクロールします。 |
Signature | scrollToTop(duration?: number) => Promise<void> |
CSS Shadow Parts
Name | Description |
---|---|
background | コンテンツの背景です。 |
scroll | コンテンツのスクロール可能なコンテナ。 |
CSS Custom Properties
Name | Description |
---|---|
--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
Name | Description |
---|---|
`` | slotなしで提供される場合、コンテンツはスクロール可能な領域に配置されます。 |
fixed | スクロールしてはいけない固定コンテンツに使用する必要があります。 |