preact-lazyimage

0.0.5 • Public • Published

preact-lazyimage

Lazy image loading made easy and simple for preact.

Installation

npm i preact-lazyimage

Drop In Replacement!

// Old
<img src="./image"></img>

// Replace with:

// Lazy Image Loading
<LazyImg src="./image"></LazyImg>

Usage

import { h } from 'preact';

import LazyImg from 'preact-lazyimage';

const App = () => <LazyImg style={{width: '40px', height: '40px'}} src="./icon.png"></LazyImg>;

render(<App/>, document.body);

Looking for lazy loading other elements? Check out preact-lazyload

Properties

<LazyImg
  onLoad={imgElement => {}}   // Triggered when image loads
  onUnload={imgElement => {}} // Triggered when image unloads
  delay={0}                   // Delay lazy loading in milliseconds
  cache={true}                // Enable/Disable caching of images; true by default
  src={src}                   // Set source for image
  legacy={false}              // Use getBoundingClientRect instead of IntersectionObservers
  preloadWidth={0}            // Preload the images with an offset width, legacy must be set to `true`
  preloadHeight={0}           // Preload the images with an offset height, legacy must be set to `true`
  {...props}                  // Remaining properties are applied onto the image element
></LazyImg>

Package Sidebar

Install

npm i preact-lazyimage

Weekly Downloads

3

Version

0.0.5

License

MIT

Unpacked Size

6.2 kB

Total Files

4

Last publish

Collaborators

  • potatoparser