@egjs/imready

中文文档
1.4.2发布于 2025/05/20MITTypeScriptESM + CJS近 30 天下载 26.9万

This module is used to wait for the image or video to be ready.

原始使用文档
文档目录15 节
  1. I'm Ready
  2. Features
  3. Documents
  4. Download and Installation
  5. How to use
  6. Events
  7. Sequence of events
  8. Supported Browsers
  9. Use polyfill if you want to use it in a lower version brows…
  10. How to start developing egjs-imready?
  11. Development Environment
  12. Linting
  13. Test
  14. Bug Report
  15. License

I'm Ready

npm version Run tests Coveralls github React Vue Vue 2 Angular Svelte

I'm Ready to check if the images or videos are loaded!

Demo / API

Features

  • Check that all images and videos in the container are loaded.
  • If you know the size of the image or video in advance, you can skip loading and adjust the width and height automatically until the actual loading is completed.
  • Support Native Lazy Loading.

Documents

Download and Installation

Download dist files from repo directly or install it via npm.

$ npm install @egjs/imready
<script src="//naver.github.io/egjs-imready/release/latest/dist/imready.min.js"></script>

How to use

import ImReady from "@egjs/imready";

const im = new ImReady().on("preReady", () => {
   // I'm pre-ready
}).on("ready", () => {
   // I'm ready
});

// check element
im.check([element]);
  • When the loading="lazy" or data-lazy="true"(external lazy loading) attribute is used, the preReadyElement(hasLoading=true) event occurs and the size is 0. When loading is complete, the readyElement(hasLoading=true) event occurs and you can get the size.
<img src="..." />
<img src="..." />
<img src="..." loading="lazy" />
<img data-lazy="true" />
  • If you use data-width and data-height attributes, the size of self, child image, and video elements is automatically adjusted until loading is complete.
<div data-width="100" data-height="100">
   <img src="..." />
   <img src="..." />
   <img src="..." />
</div>
  • If you use data-skip="true" attribute, you can omit it even if there are images in itself and child image, and video elements.
<div data-skip="true">
   <img src="..." />
   <img src="..." />
   <img src="..." />
</div>

Events

  • preReadyElement: An event occurs when the element is pre-ready (when the size is known)
  • preReady: An event occurs when all element are pre-ready (when the size is known)
  • readyElement: An event occurs when all element are ready
  • ready: An event occurs when all element are ready

Sequence of events

  • If there is no data size attribute or loading attribute

(preReadyElement => readyElement) x N => preReady => ready

  • If there is a data size attribute or a loading attribute

preReadyElement * N => (preReadyElement => readyElement) x M => preReady => readyElement(isPreReadyOver: true) x N => ready

Supported Browsers

The following are the supported browsers.

Internet ExplorerChromeFirefoxSafariiOSAndroid
9+(polyfill 8+)LatestLatestLatest7+4+(polyfill 2.2+)

Use polyfill if you want to use it in a lower version browser.

  • Array.prototype.forEach
  • Array.prototype.map
  • Array.prototype.some
  • Array.prototype.filter

How to start developing egjs-imready?

For anyone interested to develop egjs-imready, follow the instructions below.

Development Environment

1. Clone the repository

Clone the egjs-imready repository and install the dependency modules.

# Clone the repository.
$ git clone https://github.com/naver/egjs-imready.git

2. Install dependencies

# Install the dependency modules.
$ npm install

3. Build

Use npm script to build eg.ImReady

# Run webpack-dev-server for development
$ npm start

# Build
$ npm run build

# Generate jsdoc
$ npm run jsdoc

Two folders will be created after complete build is completed.

  • dist folder: Includes the imready.js and imready.min.js files.
  • doc folder: Includes API documentation. The home page for the documentation is doc/index.html.

Linting

To keep the same code style, we adopted ESLint to maintain our code quality. The rules are modified version based on Airbnb JavaScript Style Guide. Setup your editor for check or run below command for linting.

$ npm run lint

Test

Once you created a branch and done with development, you must perform a test running with npm test command before your push the code to a remote repository.

$ npm run test

Running npm test command will start Mocha tests via Karma-runner.

Bug Report

If you find a bug, please report to us opening a new Issues on GitHub.

License

egjs-imready is released under the MIT license.

Copyright (c) 2020-present NAVER Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

版本与发布记录

@egjs/imready 共发布 14 个版本,首次发布于 2020/11/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.2latest2025/05/201.5 年前
1.4.12023/02/243 年前
1.4.02023/02/243 年前
1.3.12022/11/253 年前
1.3.02021/12/244 年前
1.3.0-beta.0beta2021/12/154 年前

关于 @egjs/imready 的常见问题

@egjs/imready 是什么?

This module is used to wait for the image or video to be ready.

如何安装 @egjs/imready?

在项目目录运行 npm install @egjs/imready,或使用 pnpm add / yarn add / bun add。

@egjs/imready 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@egjs/imready 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@egjs/imready 可以商用吗?

@egjs/imready 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@egjs/imready 的下载量有多少?

根据 npm 官方下载统计,@egjs/imready 在 2026/10/13 – 2026/11/11 这 30 天内被下载 269,144 次,日均约 8,971 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@egjs/imready 还在维护吗?

最新版本 1.4.2 发布于 2025/05/20(1.5 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/11/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。