Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/David-Desmaisons/Vue.ImagesLoaded
Vue.js 2.0 directive to detect images loading
https://github.com/David-Desmaisons/Vue.ImagesLoaded
directive imagesloaded vue2
Last synced: 3 months ago
JSON representation
Vue.js 2.0 directive to detect images loading
- Host: GitHub
- URL: https://github.com/David-Desmaisons/Vue.ImagesLoaded
- Owner: David-Desmaisons
- License: mit
- Created: 2016-12-31T01:04:53.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-03T22:35:29.000Z (over 3 years ago)
- Last Synced: 2024-10-12T09:04:15.203Z (4 months ago)
- Topics: directive, imagesloaded, vue2
- Language: JavaScript
- Homepage:
- Size: 3.09 MB
- Stars: 145
- Watchers: 2
- Forks: 22
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-vue - Vue.ImagesLoaded - 检测图片加载的VueJS指令 (实用库)
- awesome - Vue.ImagesLoaded - 检测图片加载的VueJS指令 (实用库)
- awesome-vue - Vue.ImagesLoaded - Desmaisons/Vue.ImagesLoaded?style=social) - 检测图片加载的VueJS指令 (实用库)
- awesome-github-vue - Vue.ImagesLoaded - 检测图片加载的VueJS指令 (实用库)
README
# Vue.ImagesLoaded
[![GitHub open issues](https://img.shields.io/github/issues/David-Desmaisons/Vue.ImagesLoaded.svg?maxAge=2592000)](https://github.com/David-Desmaisons/Vue.ImagesLoaded/issues?q=is%3Aopen+is%3Aissue)
[![GitHub closed issues](https://img.shields.io/github/issues-closed/David-Desmaisons/Vue.ImagesLoaded.svg?maxAge=2592000)](https://github.com/David-Desmaisons/Vue.ImagesLoaded/issues?q=is%3Aissue+is%3Aclosed)
[![Npm download](https://img.shields.io/npm/dt/vue-images-loaded.svg?maxAge=2592000)](https://www.npmjs.com/package/vue-images-loaded)
[![Npm version](https://img.shields.io/npm/v/vue-images-loaded.svg?maxAge=2592000)](https://www.npmjs.com/package/vue-images-loaded)
[![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/)
[![MIT License](https://img.shields.io/github/license/David-Desmaisons/Vue.ImagesLoaded.svg)](https://github.com/David-Desmaisons/Vue.ImagesLoaded/blob/master/LICENSE)A Vue.js 2.0 directive to detect when images have been loaded, based on [imagesLoaded](http://imagesloaded.desandro.com/)
This directive allows to get a callback when children images are loaded in a container element.
Plays nicely with [vue.isotope](https://github.com/David-Desmaisons/Vue.Isotope) to allow re-layout when images are loaded.## Demo
![demo gif](vueimagesloaded.gif)
## Typical usage
```HTML
``````javascript
import imagesLoaded from 'vue-images-loaded'export default {
directives: {
imagesLoaded
},
methods: {
imageProgress(instance, image ) {
const result = image.isLoaded ? 'loaded' : 'broken';
console.log( 'image is ' + result + ' for ' + image.img.src );
}
```## Isotope Example
```HTML
{{element.name}}
{{element.id}}
```
```javascript
import imagesLoaded from 'vue-images-loaded'export default {
directives: {
imagesLoaded
},
methods: {
layout () {
this.$refs.cpt.layout('masonry');
}
}
```## API
### Using directive
- When used without argument nor modifiers:
```HTML
```
Directive value:
```javascript
function loaded(instance){
//...
}
```
loaded is a `Function` triggered after all images have been either loaded or confirmed broken.
Function parameter: ImagesLoaded instance- When used with `on` argument but no modifiers:
```HTML
```
Directive value:
```javascript
listener:{
done(instance){
//...
},
fail(instance){
//...
}
}
```
listener is an `Object` containing callback functions.
Function should be named and will received arguments as described in [Imagesloaded](http://imagesloaded.desandro.com/)- When used with `on` argument and modifier:
```HTML
```
Directive value:
```javascript
function callback(instance, img){
//...
}
```
callback is a `Function` triggered acording to modifier name `always`, `done`, `fail`, `progress`.
Function parameter: ImagesLoaded instance, and image information for `progess` only.### ImagesLoaded instance
- Properties:
- imagesLoaded.images`Array` of LoadingImage instances for each image detected
### LoadingImage instance
- Property:
- LoadingImage.img`Image` - The img element
- LoadingImage.isLoaded
`Boolean` - true when the image has succesfully loaded
## Installation
- Available through bower and npm:
``` js
npm install vue-images-loaded --save
```
``` js
bower install vue.ImagesLoaded -save
```- #### For Modules
``` js
// ES6
import imagesLoaded from 'vue-images-loaded'
...
export default {
directives: {
imagesLoaded,
}
...
// ES5
var imagesLoaded = require('vue-images-loaded')
```- #### For `` Include
Just include `vueimagesloaded.js` after `imagesloaded.pkgd.min.js` script.<br>