npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kne/iframe-resizer

v0.1.3

Published

用于自动计算内部iframe的高度.

Downloads

146

Readme

iframe-resizer

描述

用于自动计算内部iframe的高度.

安装

npm i --save @kne/iframe-resizer

概述

此库可以自动调整同域和跨域 iFrame 的高度和宽度以适合其所包含的内容。它提供了一系列功能来解决使用 iFrame 时最常见的问题,其中包括:

  • 将 iFrame 的高度和宽度调整为内容大小。
  • 适用于多个嵌套的 iFrame。
  • 跨域 iFrames 的域身份验证。
  • 提供一系列的页面大小计算方法,支持复杂的CSS布局。
  • 使用MutationObserver检测可能导致页面调整大小的 DOM 更改。
  • 检测可能导致页面调整大小的事件(窗口大小调整、CSS 动画和过渡、方向改变和鼠标事件)。
  • 通过postMessage简化 iFrame 和主机页面之间的消息传递。
  • 修复 iFrame 中的页面链接并支持 iFrame 和父页面之间的链接。
  • 提供自定义尺寸和滚动方法。
  • 向 iFrame 公开父位置和视口大小。
  • 与ViewerJS配合使用以支持 PDF 和 ODF 文档。
  • 支持 IE 11

用法

可以使用原生JavaScript 调用它;

import iFrameResize from '@kne/iframe-resizer';

const iframes = iFrameResize([{ options }], [css selector] || [iframe]);

第二个文件 ( dist/contentWindow.js ) 需要放置在 iFrame 中包含的页面中。此文件旨在作为其他人系统上的访客,因此没有依赖关系,并且在被包含页面的消息激活之前不会执行任何操作。

典型设置

正常配置是当浏览器窗口大小改变或 iFrame 内容改变时,iFrame 会调整大小。要进行此设置,您需要将 iFrame 的一个尺寸配置为百分比,并告诉库仅更新另一个尺寸。通常,您会将宽度设置为 100%,并让高度缩放以适应内容。

<style>
  iframe {
    width: 1px;
    min-width: 100%;
  }
</style>
<iframe id="myIframe" src="http://anotherdomain.com/iframe.html"></iframe>
<script>
  iFrameResize({ log: true }, '#myIframe')
</script>

注意:使用min-width设置 iFrame 的宽度,可以解决 iOS 中导致 iFrame 无法正确调整大小的问题。

示例

示例代码

API

| 属性名 | 说明 | 类型 | 默认值 | |-----|----|----|-----| | | | | |