Bài 14: Tìm hiểu Ion-App , Ion-content

Bài 14: Tìm hiểu Ion-App , Ion-content

  

Ion-App

Ứng dụng là một phần tử vùng chứa cho một ứng dụng Ionic. Chỉ nên có một <ion-app>phần tử cho mỗi dự án. Một ứng dụng có thể có nhiều thành phần Ionic bao gồm menu, tiêu đề, nội dung và chân trang. Các thành phần lớp phủ được thêm vào <ion-app>khi chúng được trình bày.

Ion-Content

Ion-Content cung cấp một vùng nội dung dễ sử dụng với một số phương pháp hữu ích để kiểm soát vùng có thể cuộn. Chỉ nên có một nội dung trong một chế độ xem.

Nội dung, cùng với nhiều thành phần Ionic khác, có thể được tùy chỉnh để sửa đổi phần đệm, lề và hơn thế nữa bằng cách sử dụng các kiểu toàn cầu được cung cấp trong CSS Utilities hoặc bằng cách tạo kiểu riêng cho nó bằng CSS và các CSS Custom Properties 

Fixed Content

Để đặt các phần tử bên ngoài vùng có thể cuộn, slot="fixed"có thể được thêm vào phần tử. Điều này sẽ hoàn toàn định vị phần tử đặt nó ở trên cùng bên trái. Để đặt phần tử ở một vị trí khác, hãy tạo kiểu cho phần tử đó bằng cách sử dụng Top,Right,buttom,left.

Usage

<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>
CopyCopied
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.

Attributecolor
Typestring | 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.

Attributeforce-overscroll
Typeboolean | 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.

Attributefullscreen
Typeboolean
Defaultfalse

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.

Attributescroll-events
Typeboolean
Defaultfalse

scrollX

Description

If you want to enable the content scrolling in the X axis, set this property to true.

Attributescroll-x
Typeboolean
Defaultfalse

scrollY

Description

If you want to disable the content scrolling in the Y axis, set this property to false.

Attributescroll-y
Typeboolean
Defaulttrue

EVents

NameDescription
ionScrollEmitted while scrolling. This event is disabled by default. Look at the property: `scrollEvents`
ionScrollEndEmitted when the scroll has ended.
ionScrollStartEmitted 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 ionScrollionScrollStartionScrollEnd for scrolling events and scrollToPoint() to scroll the content into a certain point.

SignaturegetScrollElement() => Promise<HTMLElement>

scrollByPoint

Description

Scroll by a specified X/Y distance in the component.

SignaturescrollByPoint(x: number, y: number, duration: number) => Promise<void>

scrollToBottom

Description

Scroll to the bottom of the component.

SignaturescrollToBottom(duration?: number) => Promise<void>

scrollToPoint

Description

Scroll to a specified X/Y location in the component.

SignaturescrollToPoint(x: number | undefined | null, y: number | undefined | null, duration?: number) => Promise<void>

scrollToTop

Description

Scroll 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 Custom Properties

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.
"fixed"Should be used for fixed content that should not scroll.

Đăng nhận xét

0 Nhận xét

myadcash