1.1.1 • Published 4 years ago

react-hook-lazy-image v1.1.1

Weekly downloads
14
License
MIT
Repository
github
Last release
4 years ago

一个应用React Hooks基于IntersectionObserver API实现的图片懒加载组件,具有如下特点:

  • 简单好用,配置灵活
  • 兼容主流浏览器
  • 使用React Hooks实现
  • 使用TypeScript

安装

// 使用yarn安装
yarn add react-hook-lazy-image

// 使用npm安装
npm install react-hook-lazy-image --save

使用

import React from 'react';
import LazyImage from 'react-hook-lazy-image';

const list = [ // image src url ...];

const LazyLoad:React.FC<any> = () => {
  const clientHeight = window.innerHeight;

  const style = {height: 300, width: 400, border: '1px solid #000', margin: '10px'};

  return (
    <ul style={{height: `${clientHeight-100}px`, overflow: 'auto'}}>
      {
        list.map((item, i) => (
          <LazyImage style={style} src={item} key={i} />
        ))
      }
    </ul>
  )
}

export default LazyLoad;

API

属性类型是否必填默认值描述
srcstring-图片的真实src,不传默认显示占位图
defaultSrcstringLazyImage占位图默认渲染的占位图src地址
styleobject{  width: 300,  height: 200 }图片样式
optionsobject-自定义配置,通过配置可以指定图片与特定的父级元素交叉时才去加载真实图片,祥见IntersectionObserver

最后

如果觉得好用,请点个star支持一下哈~ 如果在使用过程中有任何问题或者建议,可以在项目中提交issue,或者通过邮件与我取得联系,我会及时处理~email:lujun5068@gmail.com

1.1.1

4 years ago

1.1.0

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago