Giter VIP home page Giter VIP logo

react-progressive-image's Introduction

React Progressive Image

react-progressive-image React component for progressive image loading

Installation

Using npm:

$ npm install --save react-progressive-image

The UMD build is also available on unpkg:

<script src="https://unpkg.com/[email protected]/umd/react-progressive-image.min.js"></script>

If you use the UMD build you can find the library on window.ReactProgressiveImage.

Usage

react-progressive-image exports a single React component, ProgressiveImage, which takes a src and placeholder prop, as well as an optional onError function.

src should be the final image you want to load, and placeholder is the image you want to display until src is loaded. placeholder can be anything you want. A typical use case might involve using a smaller version of the image, an inlined version (data URI), or a loading graphic.

ProgressiveImage accepts a render callback as a child, which will be called with the placeholder first, and then src once the image has been loaded.

<ProgressiveImage src='large-image.jpg' placeholder='tiny-image.jpg'>
  {(src) => <img src={src} alt='an image'/>}
</ProgressiveImage>

It will also call the render callback with a second argument, loading, which you can use to quickly determine what image is being rendered. loading will be true when the placeholder is rendered, and false when the full image is rendered.

<ProgressiveImage src='large-image.jpg' placeholder='tiny-image.jpg'>
  {(src, loading) => (
    <img style={{ opacity: loading ? 0.5 : 1 }} src={src} alt='an image'/>
  )}
</ProgressiveImage>

react-progressive-image's People

Contributors

aweary avatar kyleshevlin avatar olarclara avatar ryan-roemer avatar wcandillon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.