{"_id":"@bestminr/vue-lazyload","_rev":"1-186d24a16bd9620062be2df611f31a96","name":"@bestminr/vue-lazyload","dist-tags":{"latest":"1.2.7"},"versions":{"1.2.7":{"name":"@bestminr/vue-lazyload","version":"1.2.7","description":"Vue module for lazy-loading images in your vue.js applications.","main":"vue-lazyload.js","unpkg":"vue-lazyload.js","scripts":{"build":"node build","lint":"eslint ./src","test":"karma start","test:types":"tsc -p types/test","test:debug":"cross-env DEBUG=true karma start"},"dependencies":{},"repository":{"type":"git","url":"https://gitlab.bestminr.com/fe/vue-lazyload.git"},"typings":"types/index.d.ts","keywords":["vue-lazyload","vue","lazyload","vue-directive"],"author":{"name":"Awe","email":"hilongjw@gmail.com"},"bugs":{"url":"https://github.com/hilongjw/vue-lazyload/issues"},"browserslist":["> 1%","last 2 versions","not ie <= 8"],"license":"MIT","devDependencies":{"assign-deep":"^0.4.7","babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-plugin-external-helpers":"^6.22.0","babel-polyfill":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-stage-0":"^6.24.1","babel-register":"^6.26.0","chai":"^4.1.2","eslint":"^4.13.1","eslint-config-standard":"^11.0.0-beta.0","eslint-plugin-import":"^2.8.0","eslint-plugin-node":"^5.2.1","eslint-plugin-promise":"^3.6.0","eslint-plugin-standard":"^3.0.1","karma":"^1.7.1","karma-chai":"^0.1.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-expect":"^1.1.3","karma-mocha":"^1.3.0","karma-rollup-preprocessor":"^5.0.2","mocha":"^4.0.1","puppeteer":"^0.13.0","rollup":"^0.51.1","rollup-plugin-babel":"^2.6.1","rollup-plugin-commonjs":"^8.4.1","rollup-plugin-node-resolve":"^3.2.0","rollup-plugin-replace":"^2.0.0","rollup-plugin-uglify":"^1.0.1","vue":"^2.5.16"},"gitHead":"2d9e06326fc187f0e42b0eba0a31e3f4b5bd3ea8","_id":"@bestminr/vue-lazyload@1.2.7","_npmVersion":"6.5.0","_nodeVersion":"8.14.0","_npmUser":{"name":"hikerpig","email":"hikerpigwinnie@gmail.com"},"dist":{"integrity":"sha512-kgDEVdsuvWHylPNvtkEDcJrzhCKZxOM9u/9ewnQKpa7MLufhChYNmVNHePhJ3j/JMX00JJSfVAuxv043uCNC2g==","shasum":"03d7a24eddc43d60ddd4722fa661168b750f44dd","tarball":"https://registry.npmjs.org/@bestminr/vue-lazyload/-/vue-lazyload-1.2.7.tgz","fileCount":25,"unpackedSize":73379,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcNA4vCRA9TVsSAnZWagAAhmEP/jwA+Zxu3FMQD5rUsJ6s\nt1UYvp9FBiIiII7q4Px1Y6lpoX3I5tlsi7TOAEzJAhjYWSwhPj9UTdRqZBd1\nsMSy/mkIFvBSBXsYuwVbhXzE5cf1Z0bcgCsSEItIgHptUUpESPjNONCBvJjn\nNtH3XU9ioxh+A8Z8jvM5hG83OLBpLzmLcnvvv1XZYJI9p3G2aJSBFnaB8of3\n3jf36ef/RtjBoRgTuN3tKPf9QQkIOH+zum5PHHBPGh9LsppBgDtuIV8v31Xc\n/98xThA6piLK7RHgVV2o8fLaWObvhnU7ov4DRbJy1z91Yoff4Yt+Q41OkYCS\nexw2O+sWbvRZ3LBCzQ9bupJpdld/M4bgHDqsO48p2j9TqRvlBRLx4wIA+YK7\nStG1k++qPZnrqFwy8FYYBdzH+pmzjw3/lxLbp48HYpE+Vsskpj+5DSe98v+R\nL08h4EIBNkT9EshekNBpu2I+NpRCE2HtiKsegaSdHTZqedGWAZHLiTzugkXb\n97GjqDLMzYANE9wzxZxf7tonXr9+p8dc+XFfRCUGjK9NG8gao/n9mJ9TTvlI\nVAqkbBspVup3ZznfweqkAMFcK5GzULi3ap2D2ztW0z7Xp7blm9fACb2BvVO/\n0RwWM0ki4JM70OvyD7NYGGOL4P/PnHqnQU6ManuWqv62epRY6xlXn5YozxwP\nsgnb\r\n=49+X\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAIMQc1GcoS+PH+M3HaNqMkwfmm1vxwM5SoOMM93sFANAiB4nZnkarbHNUWkffdM+bGBheLYo7EblubRqkmw+W0E9g=="}]},"maintainers":[{"name":"imsunhao","email":"imsunhao1994@gmail.com"},{"name":"hikerpig","email":"hikerpigwinnie@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vue-lazyload_1.2.7_1546915374894_0.7622556659357205"},"_hasShrinkwrap":false}},"time":{"created":"2019-01-08T02:42:54.742Z","1.2.7":"2019-01-08T02:42:55.001Z","modified":"2022-04-04T18:33:49.152Z"},"maintainers":[{"name":"imsunhao","email":"imsunhao1994@gmail.com"},{"name":"hikerpig","email":"hikerpigwinnie@gmail.com"}],"description":"Vue module for lazy-loading images in your vue.js applications.","keywords":["vue-lazyload","vue","lazyload","vue-directive"],"repository":{"type":"git","url":"https://gitlab.bestminr.com/fe/vue-lazyload.git"},"author":{"name":"Awe","email":"hilongjw@gmail.com"},"bugs":{"url":"https://github.com/hilongjw/vue-lazyload/issues"},"license":"MIT","readme":"# Vue-Lazyload\n\n[![Build Status](https://img.shields.io/circleci/project/hilongjw/vue-lazyload/master.svg?style=flat-square)](https://circleci.com/gh/hilongjw/vue-lazyload)\n[![npm version](https://img.shields.io/npm/v/vue-lazyload.svg?style=flat-square)](http://badge.fury.io/js/vue-lazyload)\n[![npm downloads](https://img.shields.io/npm/dm/vue-lazyload.svg?style=flat-square)](http://badge.fury.io/js/vue-lazyload)\n[![npm license](https://img.shields.io/npm/l/vue-lazyload.svg?style=flat-square)](http://badge.fury.io/js/vue-lazyload)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n[![CDNJS version](https://img.shields.io/cdnjs/v/vue-lazyload.svg)](https://cdnjs.com/libraries/vue-lazyload)\n\nVue module for lazyloading images in your applications. Some of goals of this project worth noting include:\n\n* Be lightweight, powerful and easy to use\n* Work on any image type\n* Add loading class while image is loading\n* Supports both of Vue 1.0 and Vue 2.0\n\n\n\n# Table of Contents\n\n* [___Demo___](#demo)\n* [___Requirements___](#requirements)\n* [___Installation___](#installation)\n* [___Usage___](#usage)\n * [___Constructor Options___](#constructor-options)\n * [___Implementation___](#implementation)\n    * [___Basic___](#basic)\n    * [___Css state___](#css-state)\n* [___Methods___](#methods)\n  * [__Event hook__](#event-hook)\n  * [__LazyLoadHandler__](#lazyloadhandler)\n  * [__Performance__](#performance)\n* [___Authors && Contributors___](#authors-&&-Contributors)\n* [___License___](#license)\n\n\n# Demo\n\n[___Demo___](http://hilongjw.github.io/vue-lazyload/)\n\n# Requirements\n\n- [Vue.js](https://github.com/vuejs/vue) `1.x` or `2.x`\n\n\n# Installation\n\n## npm\n\n```bash\n\n$ npm i vue-lazyload -S\n\n```\n\n## CDN\n\nCDN: [https://unpkg.com/vue-lazyload/vue-lazyload.js](https://unpkg.com/vue-lazyload/vue-lazyload.js)\n\n```html\n<script src=\"https://unpkg.com/vue-lazyload/vue-lazyload.js\"></script>\n<script>\n  Vue.use(VueLazyload)\n  ...\n</script>\n\n```\n\n# Usage\n\nmain.js:\n\n```javascript\n\nimport Vue from 'vue'\nimport App from './App.vue'\nimport VueLazyload from 'vue-lazyload'\n\nVue.use(VueLazyload)\n\n// or with options\nVue.use(VueLazyload, {\n  preLoad: 1.3,\n  error: 'dist/error.png',\n  loading: 'dist/loading.gif',\n  attempt: 1\n})\n\nnew Vue({\n  el: 'body',\n  components: {\n    App\n  }\n})\n```\n\ntemplate:\n\n```html\n<ul>\n  <li v-for=\"img in list\">\n    <img v-lazy=\"img.src\" >\n  </li>\n</ul>\n```\n\nuse `v-lazy-container` work with raw HTML\n\n```html\n<div v-lazy-container=\"{ selector: 'img' }\">\n  <img data-src=\"//domain.com/img1.jpg\">\n  <img data-src=\"//domain.com/img2.jpg\">\n  <img data-src=\"//domain.com/img3.jpg\">  \n</div>\n```\n\ncustom `error` and `loading` placeholder image\n\n```html\n<div v-lazy-container=\"{ selector: 'img', error: 'xxx.jpg', loading: 'xxx.jpg' }\">\n  <img data-src=\"//domain.com/img1.jpg\">\n  <img data-src=\"//domain.com/img2.jpg\">\n  <img data-src=\"//domain.com/img3.jpg\">  \n</div>\n```\n\n```html\n<div v-lazy-container=\"{ selector: 'img' }\">\n  <img data-src=\"//domain.com/img1.jpg\" data-error=\"xxx.jpg\">\n  <img data-src=\"//domain.com/img2.jpg\" data-loading=\"xxx.jpg\">\n  <img data-src=\"//domain.com/img3.jpg\">  \n</div>\n```\n\n## Constructor Options\n\n|key|description|default|options|\n|:---|---|---|---|\n| `preLoad`|proportion of pre-loading height|`1.3`|`Number`|\n|`error`|src of the image upon load fail|`'data-src'`|`String`\n|`loading`|src of the image while loading|`'data-src'`|`String`|\n|`attempt`|attempts count|`3`|`Number`|\n|`listenEvents`|events that you want vue listen for|`['scroll', 'wheel', 'mousewheel', 'resize', 'animationend', 'transitionend', 'touchmove']`| [Desired Listen Events](#desired-listen-events) |\n|`adapter`| dynamically modify the attribute of element |`{ }`| [Element Adapter](#element-adapter) |\n|`filter`| the image's listener filter |`{ }`| [Image listener filter](#image-listener-filter) |\n|`lazyComponent`| lazyload component | `false` | [Lazy Component](#lazy-component)\n| `dispatchEvent`|trigger the dom event|`false`|`Boolean`|\n| `throttleWait`|throttle wait|`200`|`Number`|\n| `observer`|use IntersectionObserver|`false`|`Boolean`|\n| `observerOptions`|IntersectionObserver options|{ rootMargin: '0px', threshold: 0.1 }|[IntersectionObserver](#intersectionobserver)|\n| `silent`|do not print debug info|`true`|`Boolean`|\n\n### Desired Listen Events\n\nYou can configure which events you want vue-lazyload by passing in an array\nof listener names.\n\n```javascript\nVue.use(VueLazyload, {\n  preLoad: 1.3,\n  error: 'dist/error.png',\n  loading: 'dist/loading.gif',\n  attempt: 1,\n  // the default is ['scroll', 'wheel', 'mousewheel', 'resize', 'animationend', 'transitionend']\n  listenEvents: [ 'scroll' ]\n})\n```\n\nThis is useful if you are having trouble with this plugin resetting itself to loading\nwhen you have certain animations and transitions taking place\n\n\n### Image listener filter\n\ndynamically modify the src of image\n\n```javascript\nVue.use(vueLazy, {\n    filter: {\n      progressive (listener, options) {\n          const isCDN = /qiniudn.com/\n          if (isCDN.test(listener.src)) {\n              listener.el.setAttribute('lazy-progressive', 'true')\n              listener.loading = listener.src + '?imageView2/1/w/10/h/10'\n          }\n      },\n      webp (listener, options) {\n          if (!options.supportWebp) return\n          const isCDN = /qiniudn.com/\n          if (isCDN.test(listener.src)) {\n              listener.src += '?imageView2/2/format/webp'\n          }\n      }\n    }\n})\n```\n\n\n### Element Adapter\n\n```javascript\nVue.use(vueLazy, {\n    adapter: {\n        loaded ({ bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error, Init }) {\n            // do something here\n            // example for call LoadedHandler\n            LoadedHandler(el)\n        },\n        loading (listender, Init) {\n            console.log('loading')\n        },\n        error (listender, Init) {\n            console.log('error')\n        }\n    }\n})\n```\n\n### IntersectionObserver\n\nuse [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to to improve performance of a large number of nodes.\n\n```javascript\nVue.use(vueLazy, {\n  // set observer to true\n  observer: true,\n\n  // optional\n  observerOptions: {\n    rootMargin: '0px',\n    threshold: 0.1\n  }\n})\n```\n\n\n### Lazy Component\n```javascript\nVue.use(VueLazyload, {\n  lazyComponent: true\n});\n```\n\n```html\n<lazy-component @show=\"handler\">\n  <img class=\"mini-cover\" :src=\"img.src\" width=\"100%\" height=\"400\">\n</lazy-component>\n\n<script>\n  {\n    ...\n    methods: {\n      handler (component) {\n        console.log('this component is showing')\n      }\n    }\n\n  }\n</script>\n```\n\n\n## Implementation\n\n### Basic\n\nvue-lazyload will set this img element's `src` with `imgUrl` string\n\n```html\n<script>\nexport default {\n  data () {\n    return {\n      imgObj: {\n        src: 'http://xx.com/logo.png',\n        error: 'http://xx.com/error.png',\n        loading: 'http://xx.com/loading-spin.svg'\n      },\n      imgUrl: 'http://xx.com/logo.png' // String\n    }\n  }\n}\n</script>\n\n<template>\n  <div ref=\"container\">\n     <img v-lazy=\"imgUrl\"/>\n     <div v-lazy:background-image=\"imgUrl\"></div>\n\n     <!-- with customer error and loading -->\n     <img v-lazy=\"imgObj\"/>\n     <div v-lazy:background-image=\"imgObj\"></div>\n\n     <!-- Customer scrollable element -->\n     <img v-lazy.container =\"imgUrl\"/>\n     <div v-lazy:background-image.container=\"img\"></div>\n\n    <!-- srcset -->\n    <img v-lazy=\"'img.400px.jpg'\" data-srcset=\"img.400px.jpg 400w, img.800px.jpg 800w, img.1200px.jpg 1200w\">\n    <img v-lazy=\"imgUrl\" :data-srcset=\"imgUrl' + '?size=400 400w, ' + imgUrl + ' ?size=800 800w, ' + imgUrl +'/1200.jpg 1200w'\" />\n  </div>\n</template>\n```\n\n### CSS state\n\nThere are three states while img loading\n\n`loading`  `loaded`  `error`\n\n```html\n<img src=\"imgUrl\" lazy=\"loading\">\n<img src=\"imgUrl\" lazy=\"loaded\">\n<img src=\"imgUrl\" lazy=\"error\">\n```\n\n```html\n<style>\n  img[lazy=loading] {\n    /*your style here*/\n  }\n  img[lazy=error] {\n    /*your style here*/\n  }\n  img[lazy=loaded] {\n    /*your style here*/\n  }\n  /*\n  or background-image\n  */\n  .yourclass[lazy=loading] {\n    /*your style here*/\n  }\n  .yourclass[lazy=error] {\n    /*your style here*/\n  }\n  .yourclass[lazy=loaded] {\n    /*your style here*/\n  }\n</style>\n```\n\n## Methods\n\n### Event Hook\n\n`vm.$Lazyload.$on(event, callback)`\n`vm.$Lazyload.$off(event, callback)`\n`vm.$Lazyload.$once(event, callback)`\n\n- `$on` Listen for a custom events `loading`, `loaded`, `error`\n- `$once` Listen for a custom event, but only once. The listener will be removed once it triggers for the first time.\n- `$off` Remove event listener(s).\n\n#### `vm.$Lazyload.$on`\n\n#### Arguments:\n\n * `{string} event`\n * `{Function} callback`\n\n#### Example\n\n```javascript\nvm.$Lazyload.$on('loaded', function ({ bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error }, formCache) {\n  console.log(el, src)\n})\n```\n\n#### `vm.$Lazyload.$once`\n\n#### Arguments:\n\n * `{string} event`\n * `{Function} callback`\n\n#### Example\n\n```javascript\nvm.$Lazyload.$once('loaded', function ({ el, src }) {\n  console.log(el, src)\n})\n```\n\n#### `vm.$Lazyload.$off`\n\nIf only the event is provided, remove all listeners for that event\n\n#### Arguments:\n\n * `{string} event`\n * `{Function} callback`\n\n#### Example\n\n```javascript\nfunction handler ({ el, src }, formCache) {\n  console.log(el, src)\n}\nvm.$Lazyload.$on('loaded', handler)\nvm.$Lazyload.$off('loaded', handler)\nvm.$Lazyload.$off('loaded')\n```\n\n### LazyLoadHandler\n\n`vm.$Lazyload.lazyLoadHandler`\n\nManually trigger lazy loading position calculation\n\n#### Example\n\n```javascript\n\nthis.$Lazyload.lazyLoadHandler()\n\n```\n\n### Performance\n\n```javascript\nthis.$Lazyload.$on('loaded', function (listener) {\n  console.table(this.$Lazyload.performance())\n})\n```\n\n![performance-demo](http://ww1.sinaimg.cn/large/69402bf8gw1fbo62ocvlaj213k09w78w.jpg)\n\n### Dynamic switching pictures\n\n```vue\n <img v-lazy=\"lazyImg\" :key=\"lazyImg.src\">\n```\n\n\n# Authors && Contributors\n\n- [hilongjw](https://github.com/hilongjw)\n- [imcvampire](https://github.com/imcvampire)\n- [darrynten](https://github.com/darrynten)\n- [biluochun](https://github.com/biluochun)\n- [whwnow](https://github.com/whwnow)\n- [Leopoldthecoder](https://github.com/Leopoldthecoder)\n- [michalbcz](https://github.com/michalbcz)\n- [blue0728](https://github.com/blue0728)\n- [JounQin](https://github.com/JounQin)\n- [llissery](https://github.com/llissery)\n- [mega667](https://github.com/mega667)\n- [RobinCK](https://github.com/RobinCK)\n- [GallenHu](https://github.com/GallenHu)\n\n# License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n","readmeFilename":"README.md"}