3.0.0 • Published 2 years ago

react-simple-img v3.0.0

Weekly downloads
2,698
License
Mit
Repository
github
Last release
2 years ago

Features

  • Speed up initial page loads by loading only images above the fold
  • Responsive with placeholders and animations
  • Support Priority Hints with importance attribute
  • Smart download logic using IntersectionObserver
  • Simple usage and tiny size includes polyfill (minified + gzipped)

Install

npm install react-simple-img

Quickstart

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

export default () => <SimpleImg height={500} src="your image path" />;

API

🔗 SimpleImg

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

PropTypeRequiredDescription
srcstringThe large image source
srcSetstringeg: large.jpg 2x, small.jpg Reference for examples
sizesstringeg: (max-width: 320px) 280px, (max-width: 480px) 440px Reference for examples
importancestringPriority 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
placeholderstringPlaceholder image source (svg, jpg, png...) or css color value (white, linear-gradient(blue, pink)), set to false will remove placeholder.
applyAspectRatiobooleanImage will scale automatically with aspect ratio. Note: width and height will need to be supplied
animationDurationnumberanimation duration in seconds
imgStyleobjectInline 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

  • config: (Object) this argument is optional
 - [root]: The element that is used as the viewport for checking
   visibility of the target. Must be the ancestor of the target. Defaults
   to the browser viewport if not specified or if null.

 - [rootMargin]: Margin around the root. Can have values similar to the
   CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom,
   left). If the root element is specified, the values can be
   percentages. This set of values serves to grow or shrink each side of
   the root element's bounding box before computing intersections.
   Defaults to all zeros.

 - [threshold]: Either a single number or an array of numbers which
   indicate at what percentage of the target's visibility the observer's
   callback should be executed. If you only want to detect when
   visibility passes the 50% mark, you can use a value of 0.5. If you
   want the callback run every time visibility passes another 25%, you
   would specify the array [0, 0.25, 0.5, 0.75, 1]. The default is 0
   (meaning as soon as even one pixel is visible, the callback will be
   run). A value of 1.0 means that the threshold isn't considered passed
   until every pixel is visible.
  • disableAnimateCachedImg: (boolean) this argument is optional
 - if you want to disable the reveal animation after image have been cached
 - Determining whether images have been cached is achieved using `sessionStorage`.
   Setting this to true will have no effect for users with privacy settings enabled 
   in their browsers that block the use of `sessionStorage`.
    
 
  • logConsoleError: (boolean) this argument is optional
 - if you want to log errors in browser console when image fetch failed, then set the value to true.
 

Sponsors

Thank you very much for those kind people with their sponsorship to this project.

3.0.0

2 years ago

2.3.9

4 years ago

2.3.8

4 years ago

2.3.8-beta.1

4 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.5-beta.1

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.2-beta.1

5 years ago

2.3.1

5 years ago

2.3.1-beta.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.9

5 years ago

2.1.8

5 years ago

2.1.7

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.1.0-beta.3

5 years ago

2.1.0-beta.2

5 years ago

2.1.0-beta.1

5 years ago

2.0.0

5 years ago

2.0.0-beta.2

5 years ago

2.0.0-beta.1

5 years ago

1.14.0

5 years ago

1.14.0-beta.3

5 years ago

1.14.0-beta.2

5 years ago

1.13.2

5 years ago

1.13.1

5 years ago

1.14.0-beta.1

5 years ago

1.13.0

5 years ago

1.13.0-beta.1

5 years ago

1.12.0

5 years ago

1.12.0-beta.1

5 years ago

1.11.0

5 years ago

1.10.5

5 years ago

1.10.4

5 years ago

1.10.3

5 years ago

1.10.2

5 years ago

1.10.1

5 years ago

1.10.0

5 years ago

1.9.3-beta.2

5 years ago

1.9.3-beta.1

5 years ago

1.9.2

5 years ago

1.9.1

5 years ago

1.9.0

5 years ago

1.8.4

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.6.0-beta.2

5 years ago

1.6.0-beta.1

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.1

5 years ago

1.4.6-beta.2

5 years ago

1.5.0

5 years ago

1.5.0-beta.2

5 years ago

1.5.0-beta.1

5 years ago

1.4.6-beta.1

5 years ago

1.4.5

5 years ago

1.4.5-beta.4

5 years ago

1.4.5-beta.3

5 years ago

1.4.5-beta.2

5 years ago

1.4.4

5 years ago

1.4.4-beta.3

5 years ago

1.4.4-beta.2

5 years ago

1.4.4-beta.1

5 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.16

6 years ago

1.3.15

6 years ago

1.3.14

6 years ago

1.3.13

6 years ago

1.3.13-beta.2

6 years ago

1.3.13-beta.1

6 years ago

1.3.12

6 years ago

1.3.11

6 years ago

1.3.10

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.6-beta.2

6 years ago

1.3.6-beta.1

6 years ago

1.3.5

6 years ago

1.3.5-beta.1

6 years ago

1.3.4

6 years ago

1.3.4-beta.1

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.2-beta.2

6 years ago

1.3.2-beta.1

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2-beta.4

6 years ago

1.2.2-beta.2

6 years ago

1.2.2-beta.1

6 years ago

1.2.1

6 years ago

1.2.1-beta.5

6 years ago

1.2.1-beta.4

6 years ago

1.2.1-beta.3

6 years ago

1.2.1-beta.2

6 years ago

1.2.1-beta.1

6 years ago

1.2.0

6 years ago

1.2.0-beta.3

6 years ago

1.2.0-beta.2

6 years ago

1.2.0-beta.1

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3-beta.3

6 years ago

1.0.3-beta.2

6 years ago

1.0.3-beta.1

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1-beta.20

6 years ago

0.0.1-beta.19

6 years ago

0.0.1-beta.18

6 years ago

0.0.1-beta.17

6 years ago

0.0.1-beta.16

6 years ago

0.0.1-beta.15

6 years ago

0.0.1-beta.14

6 years ago

0.0.1-beta.13

6 years ago

0.0.1-beta.12

6 years ago

0.0.1-beta.11

6 years ago

0.0.1-beta.10

6 years ago

0.0.1-beta.9

6 years ago

0.0.1-beta.8

6 years ago

0.0.1-beta.7

6 years ago

0.0.1-beta.6

6 years ago

0.0.1-beta.5

6 years ago

0.0.1-beta.4

6 years ago

0.0.1-beta.3

6 years ago

0.0.1-beta.2

6 years ago

0.0.1-beta.1

6 years ago

0.0.1

6 years ago