1.0.6 • Published 3 years ago

vue-cooler-lazyload v1.0.6

Weekly downloads
15
License
MIT
Repository
github
Last release
3 years ago

Vue-cooler-lazyload

npm version npm downloads npm license PRs Welcome

A vue plugin which support lazyload image and background-image. Here are the advantages:

  • Be lighterweight, just do one thing is that lazyload
  • use the browser native API Intersectionobserver, better performance
  • offer hooks which we could use before and after image loaded

Demo

npm install
npm run dev

Requirements

  • Vue 2.x

Installation

npm

npm install vue-cooler-lazyload

Usage

main.js:

import Vue from 'vue';
import lazyloadPlugin from 'vue-cooler-lazyload';

Vue.use(lazyloadPlugin);

template:

<div>
  <img v-lazyload="imageurl" />
  <div v-lazyload="imageurl"></div>
</div>

if v-lazyload directive is used in div Element, image would be background-image attribute.

Plugin Options

keydescriptiondefaultoptions
borderthe viewport you want to listen{top: 0, bottom: 0, left: 0, right: 0}(window){top, bottom, left, right}
thresholdthe proportion of element insert into viewport0(0 means that when a element go into the viewport, image begins load)0~1
cacheImagerender image at once if the image has been loaded before and don't excuted hooksfalseboolean
beforeLoadfunction that would be excuted when dom loadednullFunction(el: HTMLElement): void
afterLoadfunction that would be excuted when image loadednullFunction(el: HTMLElement): void

Compatibility

The compatibility of this plugin depends on compatibility of IntersectionObserver

License

MIT

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago