react-better-image

1.0.0 • Public • Published

react-better-image

A progressive image component with a better user experience.

NPM JavaScript Style Guide

Install

npm install --save react-better-image

Usage

import React, { Component } from 'react'
 
import BetterImage from 'react-better-image'
 
class Example extends Component {
  render () {
    return (
      <BetterImage
        source={'your source image url'}
        placeholder={'a loading component or a thumbnail image url, also can be a func like () => <Loading/>'}
        alt={'alt'}
        onload={(CurrentDOMElement) => {'img onload event, the current dom element be observed as param'}}
        enter={() => {'Image enters the viewable area'}}
        leave={() => {'Image leaves the viewable area'}}
        onlyEnter={false} // if true,will only emit the enter callbackleave function will not be called
        root={'default null, your viewable area target dom element'}
        rootMargin={'default "0px, 0px"'}
      />
    )
  }
}

More

if you want to understand the implementation principle of this component. And the settings of root, rootMargin and other parameters.

please refer to --> intersection-observer.

License

MIT © bobi

Readme

Keywords

none

Package Sidebar

Install

npm i react-better-image

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

63.6 kB

Total Files

6

Last publish

Collaborators

  • huangteng