1.1.3 • Published 4 years ago

vue-simple-lazyload v1.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

vue-simple-lazyload

A pure lazyload plugin for vue or nuxt

Support

<img src="" /> && background-image: url();

Link

demo npm

Usage

$ yarn add vue-simple-lazyload -S
// or
$ npm i vue-simple-lazyload -S

options Intersection_Observer_API

eg. rootMargin: '50px' can preload img before 50px

Vue

Component

  1. main.js

    import Vue from 'vue'
    import { VueImgLazy } from 'vue-simple-lazyload'
    
    Vue.use(VueImgLazy, {
      rootMargin: '50px'
    })
  2. template

    <ImgLazy :imgUrl="" :bgColor="" :lazyloadContainer="" :lazyloadImg="" :placeholderFigure=""></ImgLazy>
  3. Props

    PropsDescriptionDefaultOpt/Required
    imgUrlImage url''Required
    bgColorBackground color''Optional
    lazyloadContainerContainer class'' // has default styleOptional
    lazyloadImgImage Class'' // has default styleOptional
    placeholderFigurePlaceholder imageA base64 transparent figureOptional

Directive

v-lazy (for <img src="" />)
  1. main.js

    import Vue from 'vue'
    import { VueLazy } from 'vue-simple-lazyload'
    
    Vue.use(VueLazy, {
      rootMargin: '50px'
    })
  2. template

    <div v-lazy="$imgUrl"
        :style="{
          backgroundColor: $bgColor
        }"
        class="lazyload-container">
        <img :src="$placeholderFigure" class="lazyload-img" />
    </div>
    
    /*css. This is also the default style of the VueImgLazy component*/
    .lazyload-container {
      transition: background-color .5s ease-in-out .3s;
      width: 400px;
      height: 200px;
    }
    .lazyload-img  {
      transition: opacity .5s ease-in-out .3s;
      opacity: 0;
      width: 100%;
      height: 100%;
    }
v-lazy:bgimg (for background-image: url();)
  1. main.js

    import Vue from 'vue'
    import { VueLazy } from 'vue-simple-lazyload'
    
    Vue.use(VueLazy, {
      rootMargin: '50px'
    })
  2. template

    <div v-lazy:bgimg="$imgUrl"
        :style="{
          backgroundColor: $bgColor
        }"
        class="lazyload-container">
    </div>
    
    /*css. This is also the default style of the VueImgLazy component*/
    .lazyload-container {
      transition: background-color .5s ease-in-out .3s;
      width: 400px;
      height: 200px;
    }

nuxt

  1. ~/plugins/lazyload.js

    import Vue from 'vue'
    import { VueLazy, VueImgLazy } from 'vue-simple-lazyload'
    
    Vue.use(VueLazy, {
      rootMargin: '50px'
    })
    // or
    Vue.use(VueImgLazy, {
      rootMargin: '50px'
    })
  2. nuxt.config.js

    ...
     plugins: [
       { src: '~/plugins/lazyLoad', mode: 'client' }
     ],
    ...

Required

This project base on Intersection_Observer_API. Need import polyfill if necessary.

TODO

  1. Add nuxt modules
1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago