1.1.8 • Published 1 year ago

lazy-image-renderer v1.1.8

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year 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

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.2

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.0

3 years ago