• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue.js 2.0 directive to detect images loading

Vue.ImagesLoaded

GitHub open issues GitHub closed issues Npm download Npm version vue2 MIT License

A Vue.js 2.0 directive to detect when images have been loaded, based on imagesLoaded

This directive allows to get a callback when children images are loaded in a container element.
Plays nicely with vue.isotope to allow re-layout when images are loaded.

Demo

demo gif

Typical usage

<div v-images-loaded:on.progress="imageProgress">
	<div v-for="element in list">
		<img :src="element.src">
	</div>
</div>
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

<isotope ref="cpt" :options='getOptions()' v-images-loaded:on.progress="layout" :list="list">
    <div v-for="element in list" :key="element.id"  @click="selected=element">
        {{element.name}}
        <br>
        {{element.id}}
        <img :src="element.src" alt="Not found">
    </div>
</isotope>
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:
<div v-images-loaded:"loaded">

Directive value:

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:
<div v-images-loaded.on:"listener">

Directive value:

listener:{
    done(instance){
        //...
    },
    fail(instance){
        //...
    }
}

listener is an Object containing callback functions.
Function should be named and will received arguments as described in Imagesloaded

  • When used with on argument and modifier:
<div v-images-loaded.on.progress:"callback">

Directive value:

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:
 npm install vue-images-loaded --save
 bower install vue.ImagesLoaded -save
  • For Modules

    // ES6
    import imagesLoaded from 'vue-images-loaded'
    ...
    export default {
          directives: {
              imagesLoaded,
          }
      ...
    
    // ES5
    var imagesLoaded = require('vue-images-loaded')
  • For <script> Include

    Just include vueimagesloaded.js after imagesloaded.pkgd.min.js script.

More Repositories

1

Vue.D3.tree

Vue component to display tree based on D3.js layout.
Vue
868
star
2

draggable-example

vue.draggable example
Vue
510
star
3

Vue.Isotope

πŸ“± Vue component for isotope filter & sort magical layouts
JavaScript
345
star
4

Vue.resize

Vue directive to detect resize events with deboucing and throttling capacity.
JavaScript
327
star
5

RateLimiter

C# rate limiting utility
C#
278
star
6

vue-plotly

πŸ“ˆ vue wrapper for plotly.js
JavaScript
254
star
7

vue-cli-plugin-component

πŸ› οΈ vue-cli 3 plugin to create component
JavaScript
88
star
8

Vue.D3.sunburst

Vue sunburst component based on D3.js
Vue
62
star
9

ComponentFixture

πŸ› οΈInteractive sandox playground for vue components
Vue
51
star
10

Vue-Semantic-Modal

Vue modal component for Semantic-Ui no jquery
JavaScript
45
star
11

DiscogsClient

Discogs API C# Client
C#
41
star
12

CodeDependencyScanner

.Net assembly code depency inspector
JavaScript
37
star
13

ComposableAsync

Create, compose and inject asynchronous behaviors in .Net Framework and .Net Core.
C#
31
star
14

MVVM-for-awesomium

MVVM binding framework between C# ViewModel and awesomium HTLM-javascript view
C#
16
star
15

RestSharpHelper

Small library helper for RestSharp inclusing rate limit, OAuth, helper for async download among others
C#
7
star
16

Music.Cover.Finder

C# application that display music cover art
C#
7
star
17

MusicCollection

Music Library and Player
C#
6
star
18

Retlang

C#
5
star
19

vue-ajax-handler

Ultra minimal generic vue component to deal with ajax loading
JavaScript
2
star
20

datascience_detroit_bligth

Predicting Detroit Blight using Machine Learning
Jupyter Notebook
2
star
21

David-Desmaisons

1
star
22

tape-tests

Minimal repository to show problem with esm modules and windows
JavaScript
1
star
23

ScreenSaver

JavaScript
1
star
24

MovieExplorer

C#
1
star
25

ProxyDebugLogger

Create proxy that logs method call. For debug purpose.
JavaScript
1
star
26

MoreCollection

C# collection framework
C#
1
star