1.1.8 • Published 2 months ago

lazy-image-renderer v1.1.8

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

lazy-image-renderer 🎨

Version License

Description

A React component that optimizes image loading using Intersection Observer, providing smooth transitions and improved performance for lazy image rendering.

lazy-loading

Get started

npm install lazy-image-renderer --save

or

yarn add lazy-image-renderer

Use

import { LazyImageRenderer } from 'lazy-image-renderer';

Examples

Default

<LazyImageRenderer src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg' />

Responsive image source

<LazyImageRenderer
  sizes='(max-width: 600px) 120px, (max-width: 900px) 193px, 278px'
  src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg'
  srcSet='http://jnisperuza-images.infinityfreeapp.com/vangogh-sm.jpg 120w, http://jnisperuza-images.infinityfreeapp.com/vangogh.jpg 193w, http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg 278w'
/>

Effects

Blur

<LazyImageRenderer
  effect='blur'
  effectDuration={0.5}
  objectFit='cover'
  src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg'
/>

blur-effect

Black and white

<LazyImageRenderer
  effect='black-and-white'
  objectFit='cover'
  src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg'
/>

black-and-white-effect

Opacity

<LazyImageRenderer
  effect='opacity'
  objectFit='cover'
  src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg'
/>

Effect Duration

The duration will be read in seconds from a number, for instance: 1 = 1 second, 0.5 = 500 milliseconds.

<LazyImageRenderer
  effect='opacity'
  effectDuration={0.4}
  objectFit='cover'
  src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg'
/>

Intersection Options

<LazyImageRenderer
  effect='opacity'
  objectFit='cover'
  src='http://jnisperuza-images.infinityfreeapp.com/vangogh-lg.jpg'
  intersectionOptions={{
    rootMargin: '100px',
    threshold: 0.15,
  }}
/>

ezgif com-gif-maker

Properties

src is the only required property, all other properties are optional.

PropertytypeDescription
namestringSpecifies a name for a wrapper component.
classNamestringSpecifies a custom class for a wrapper component, is possible to send multiple class separate with spaces ("foo baz").
altstringSpecifies an alternate text for an image.
crossoriginanonymous, use-credentialsAllow images from third-party sites that allow cross-origin access to be used with canvas.
longdescstringSpecifies a URL to a detailed description of an image.
objectFitfill, contain, cover, scale-down, noneProperty is used to specify how an img or video should be resized to fit its container.
referrerpolicyno-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, unsafe-urlSpecifies which referrer information to use when fetching an image.
ismapbooleanWhen present, it specifies that the image is part of a server-side image map (an image map is an image with clickable areas).
usemapstringSpecifies an image as a client-side image map.
srcstringrequired Specifies the path to the image.
sizesstringSpecifies image sizes for different page layouts.
srcSetstring[]Specifies a list of image files to use in different situations.
heightnumber, stringSpecifies the height of an image, *If it is not sent, the value of the parent is taken.
widthnumber, stringSpecifies the width of an image, *If it is not sent, the value of the parent is taken.
effectblur, black-and-white, opacitySpecifies the transition of how the image appears. It has a time of 8 milliseconds.
effectDurationnumberSpecifies the transition time (expressed in seconds) of the image appearance.
intersectionOptionsIntersectionOptionsThe IntersectionObserver interface of the Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport.
draggablebooleanWhen set to true, the draggable attribute allows users to click and drag the associated element using their mouse or touch input, providing an interactive and user-friendly interface for elements.

Read more: #dom-intersectionobserver

interface IntersectionOptions {
  root?: Element | null;
  rootMargin?: string;
  threshold?: number | number[];
}

Live example

https://stackblitz.com/edit/lazy-image-renderer?file=App.tsx

Author ✒️

1.1.8

2 months ago

1.1.7

2 months ago

1.1.6

2 months ago

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.1.2

9 months ago

1.0.22

10 months ago

1.0.21

10 months ago

1.0.20

10 months ago

1.0.26

10 months ago

1.0.25

10 months ago

1.0.24

10 months ago

1.0.23

10 months ago

1.0.28

10 months ago

1.0.27

10 months ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.0

1 year ago