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-image-lazy-load

v1.3.0

Published

React Image Lazy Load plug-in with loader/placeholder image option - Forked from react-lazy-load plug-in - https://github.com/loktar00/react-lazy-load

Downloads

166

Readme

React Image Lazy Load Component

React Image Lazy Load is easy to use React component which helps you defer loading Images in predictable way. It's fast, works in IE8+, 6KB minified and uses debounce function by default. You can also use component inside scrolling container, such as div with scrollbar. It will be found automatically. Check out an example.

React Image Lazy Load plug-in forked from react-lazy-load

This version has below addition on top of original plug-in:

build status dependency status npm downloads

Installation

React Lazy Load requires React 0.14 or later.

npm install --save react-image-lazy-load

Examples

Usage

import React from 'react';
import LazyLoad from 'react-image-lazy-load';

const MyComponent = () => (
  <div>
    Scroll to load images.
    <div className="filler" />
    <LazyLoad height={762} offsetVertical={300} loaderImage originalSrc="http://apod.nasa.gov/apod/image/1502/HDR_MVMQ20Feb2015ouellet1024.jpg" imageProps={{
      src: require('../../images/ring.gif'),
      alt: "DR_MVMQ20Feb2015ouellet1024.jpg",
      ref: "image",
      className: "className"
    }} />
    <div className="filler" />
    <LazyLoad height={683} offsetTop={200} imageProps={{
      src: "http://apod.nasa.gov/apod/image/1502/2015_02_20_conj_bourque1024.jpg",
      alt: "2015_02_20_conj_bourque1024.jpg",
      ref: "image",
      className: "className"
    }} />
    <div className="filler" />
    <LazyLoad height={480} offsetHorizontal={50} imageProps={{
      src: "http://apod.nasa.gov/apod/image/1502/MarsPlume_jaeschke_480.gif",
      alt: "1502/MarsPlume_jaeschke_480.gif",
      ref: "image",
      className: "className"
    }} />
    <div className="filler" />
    <LazyLoad
      height={720}
      onContentVisible={() => console.log('look ma I have been lazyloaded!')} originalSrc="http://apod.nasa.gov/apod/image/1502/ToadSky_Lane_1080_annotated.jpg" loaderImage={true} imageProps={{
        src: require('../../images/ring.gif'),
        alt: "ToadSky_Lane_1080_annotated.jpg",
        ref: "image",
        className: "image"
      }} />
    <div className="filler" />
  </div>
);

Props

imageProps

Type: Object Required: Yes

The imageProps is a required props for this plug-in to work. This can except any possible HTML attributes for img tag which also includes data attributes and React specific ref and className.

loaderImage

Type: Boolean Default: false

The loaderImage is a Boolean prop to define if the image has to have a loader/placeholder image. If this set to true then prop originalSrc becomes required. If loaderImage is set to true then loader/placeholder image can be set to 'src' attribute of imageProps prop.

originalSrc

Type: String

originalSrc is useful when you want the image tag to be loaded first with any loader/placeholder image. This prop becomes required if prop loaderImage is set to true for the component. This expect the original image SRC which should replace the loader/placeholder image once original image gets loaded.

addNoScript

Type: Boolean Default: true

addNoScript controls adding a noscript Tag to wrap the actual image so that it supports SEO requirements to inndex actual Images.

offset

Type: Number|String Default: 0

Aliases: threshold

The offset option allows you to specify how far below, above, to the left, and to the right of the viewport you want to begin displaying your content. If you specify 0, your content will be displayed as soon as it is visible in the viewport, if you want to load 1000px below or above the viewport, use 1000.

offsetVertical

Type: Number|String Default: offset's value

The offsetVertical option allows you to specify how far above and below the viewport you want to begin displaying your content.

offsetHorizontal

Type: Number|String Default: offset's value

The offsetHorizontal option allows you to specify how far to the left and right of the viewport you want to begin displaying your contet.

offsetTop

Type: Number|String Default: offsetVertical's value

The offsetTop option allows you to specify how far above the viewport you want to begin displaying your content.

offsetBottom

Type: Number|String Default: offsetVertical's value

The offsetBottom option allows you to specify how far below the viewport you want to begin displaying your content.

offsetLeft

Type: Number|String Default: offsetVertical's value

The offsetLeft option allows you to specify how far to left of the viewport you want to begin displaying your content.

offsetRight

Type: Number|String Default: offsetVertical's value

The offsetRight option allows you to specify how far to the right of the viewport you want to begin displaying your content.

throttle

Type: Number|String Default: 250

The throttle is managed by an internal function that prevents performance issues from continuous firing of scroll events. Using a throttle will set a small timeout when the user scrolls and will keep throttling until the user stops. The default is 250 milliseconds.

debounce

Type: Boolean Default: true

By default the throttling function is actually a debounce function so that the checking function is only triggered after a user stops scrolling. To use traditional throttling where it will only check the loadable content every throttle milliseconds, set debounce to false.

height

Type: String|Number Default: 100

This is used to set the elements height even when it has no content.

onContentVisible

Type Function

A callback function to execute when the content appears on the screen.