0.2.1 • Published 7 years ago
my-lazyload v0.2.1
LazyLoad
a component to lazyload images
Feature
- wirtten in native javascript
- use intersectionObserver when support, fallback listen scroll event to check image's getBoundingClientRect
- use debounce to decrease scroll event
- when load image, remove image from observe
- when all images loaded, remove observer or scroll event
- defer load images when use data-defer
Installation
npm i my-lazyload -S
Usage
<img src="images/defalut.png" data-src="images/real.jpg" data-defer="5000"/>
import {LazyLoad} from 'my-lazyload';
new LazyLoad({
imgSelector:'img[data-src]',
threshold:100
})
Params
Parameter | Type | Default | Description |
---|---|---|---|
data-src | string | image's attr to store url | |
data-defer | number | image's load after defer time, not scroll | |
imgSelector | string | imgdata-src | the images selector, used in document.querySelectorAll |
thresold | number | 0 | how pixels before viewport to load images |
container | function | window | the callback function after toast hide |