beekai-oss / react-simple-img

🌅 React lazy load images with IntersectionObserver API and Priority Hints
MIT License
989 stars 41 forks source link
animation hints images-lazy intersectionobserver lazyload lazyload-images placeholder priority responsive-images

React Simple Img Logo - Animated lazy loading - on demand

React Simple Img

Smart react lazy load image with IntersectionObserver API, Priority Hints and animations

[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=React+Lazy+load+images+with+Intersection+Observer+API&url=https://github.com/bluebill1049/react-simple-img) [![CircleCI](https://coveralls.io/repos/github/bluebill1049/react-simple-img/badge.svg?branch=master)](https://coveralls.io/github/bluebill1049/react-simple-img?branch=master) [![npm downloads](https://img.shields.io/npm/dm/react-simple-img.svg?style=flat-square)](https://www.npmjs.com/package/react-simple-img) [![npm](https://img.shields.io/npm/dt/react-simple-img.svg?style=flat-square)](https://www.npmjs.com/package/react-simple-img)

Features

Install

npm install react-simple-img

Quickstart

import { SimpleImg } from 'react-simple-img';

export default () => <SimpleImg height={500} src="https://github.com/beekai-oss/react-simple-img/raw/master/your image path" />;

API

🔗 SimpleImg

Image component working similar with standard img tag and with the following props.

Prop Type Required Description
src string The large image source
srcSet string eg: large.jpg 2x, small.jpg
Reference for examples
sizes string eg: (max-width: 320px) 280px, (max-width: 480px) 440px
Reference for examples
importance string Priority Hints with "low" or "auto": set to "auto" will load image after load event, otherwise "low" will load images after load event and lazy load with intersection observer
placeholder string Placeholder image source (svg, jpg, png...) or css color value (white, linear-gradient(blue, pink)), set to false will remove placeholder.
applyAspectRatio boolean Image will scale automatically with aspect ratio. Note: width and height will need to be supplied
animationDuration number animation duration in seconds
imgStyle object Inline styles for the <img> element.
🔗 initSimpleImg([config], disableAnimateCachedImg = false, logConsoleError = false) optional

This function is only required, when you want to customise intersection observer configuration.

Arguments

By the makers of BEEKAI

We also make BEEKAI. Build the next-generation forms with modern technology and best in class user experience and accessibility.