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

react-cool-image

v0.5.3

Published

一个可懒加载,动画友好的图片组件

Downloads

168

Readme

React 图片组件

动画友好的图片组件,支持懒加载、默认图片显示、错误回退等,使用 七牛阿里云 存储做图片格式优化,默认加载 webp 格式,使用 react-cool-inview 做懒加载方案,具体参考 Intersection Observer

npm version npm downloads gzip size

Requirement

It requires react v16.8+.

Installation

This package is distributed via npm.

$ yarn add react-cool-image
# or
$ npm install --save react-cool-image

Quick Start

import Image from 'react-cool-image'
import 'react-cool-image/dist/style.scss'
// or
// import 'react-cool-image/dist/style.css'

const App = () => <Image width={300} height={100} src="https://xxx.png" />

通过 CDN 使用

除了可以通过 npm 安装之外,你也可以直接使用 CDN 资源,react-cool-image 页提供了 umd 格式的代码产物。

<link
  href="https://cdn.jsdelivr.net/npm/[email protected]/dist/style.css"
/>

注:css0.4.0 版本提供,0.4.0 以下使用 inline style

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js"></script>

API

支持 lazy-loadprogressive image loading(带虚化效果),如果浏览器支持 webp,会自动使用 webp 格式的图片。

| Prop | Type | Default | Description | | --------------- | ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | | src | string | | 图片地址 It's required. Support formats | | error | string | | 错误时显示图片的地址 Support formats | | placeholder | string | | Placeholder image source. Support formats | | webp | boolean | true | 是否使用 webp | | format | boolean | Format | true | 是否使用 云存储 格式化,为 true 时默认取全局 CDN 配置 | | width | number | | 宽度 单位 px | | height | number | | 高度,单位 px | | lazy | boolean | string | true | Turn on/off lazy loading. 目前可选值 booleanthumbskeleton | | observerOptions | object | {} | See the ObserverOptions section. | | ... | | | Find more props and events. |

Attention

  • lazythumb 地址时才会有缩略图虚化效果
  • formattrue 时,或者 src 包含图片格式化参数时,format 默认不起作用
  • widthheight 并不是图片最终的宽高。只是该组件用来计算 placeholder 宽高的基数。 计算公式为 宽 = 父元素的宽,高 = 宽 * (height / width)
  • 如果 lazy 不为空,widthheight 是建议设置的

Format

云存储图片格式化参数,可覆盖默认全局 CDN 配置参数,默认阿里云图片格式配置

| 名称 | 类型 | 说明 | 默认值 | | ----------- | ------ | --------------------------------------------------------------------------------- | --------------------------------------------- | | thumb | string | 缩略图格式化参数,示例:x-oss-process=image/resize,p_15 | x-oss-process=image/resize,p_15 | | thumbWebp | string | 缩略图 webp 格式参数,示例:x-oss-process=image/resize,p_15/format,webp | x-oss-process=image/resize,p_15/format,webp | | webp | string | 图片 webp 格式参数,示例:x-oss-process=image/format,webp | x-oss-process=image/format,webp |

observerOptions

默认值

{
  "rootMargin": "20px",
  "unobserveOnEnter": true
}

其他参数参考:react-cool-inview API