0.2.1 • Published 7 years ago

my-lazyload v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

LazyLoad

a component to lazyload images

Feature

  1. wirtten in native javascript
  2. use intersectionObserver when support, fallback listen scroll event to check image's getBoundingClientRect
  3. use debounce to decrease scroll event
  4. when load image, remove image from observe
  5. when all images loaded, remove observer or scroll event
  6. 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

ParameterTypeDefaultDescription
data-srcstringimage's attr to store url
data-defernumberimage's load after defer time, not scroll
imgSelectorstringimgdata-srcthe images selector, used in document.querySelectorAll
thresoldnumber0how pixels before viewport to load images
containerfunctionwindowthe callback function after toast hide
0.2.1

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.0.1

7 years ago