@1milligram/frame 中文文档教程

发布于 3年前 浏览 28 项目主页 更新于 3年前

Frame

一个在元素内包裹iframe的React组件:

  • [x] The iframe is only loaded when it is visible in the screen
  • [x] The iframe is resized automatically when its content resizes

由于跨域(CORS)问题,它只支持src所属的iframe您网站的同一域。

Usage

  1. Install the package:
$ npm install @1milligram/frame
  1. Using the Frame component:
import { Frame } from '@1milligram/frame';
import '@1milligram/frame/lib/styles/index.css';

<Frame url="/path/to/iframe" />;

Options

设置框架高度

出于任何原因,您想自己计算以调整框架高度:

const setFrameHeight = (doc: Document) => {
    // `doc` is the document instance of the iframe content
    return doc.body.scrollHeight;
};

<Frame setFrameHeight={setFrameHeight} />;

Frame

A React component that wraps an iframe inside an element:

  • [x] The iframe is only loaded when it is visible in the screen
  • [x] The iframe is resized automatically when its content resizes

Due to the cross domain (CORS) issue, it only supports iframe whose src belongs to the same domain of your site.

Usage

  1. Install the package:
$ npm install @1milligram/frame
  1. Using the Frame component:
import { Frame } from '@1milligram/frame';
import '@1milligram/frame/lib/styles/index.css';

<Frame url="/path/to/iframe" />;

Options

Setting the frame height

For any reason that you would like to do your own calculation to adjust the frame height:

const setFrameHeight = (doc: Document) => {
    // `doc` is the document instance of the iframe content
    return doc.body.scrollHeight;
};

<Frame setFrameHeight={setFrameHeight} />;
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文