Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: support for imagesLoaded option #63

Open
kevinzweerink opened this issue Oct 21, 2020 · 2 comments
Open

Request: support for imagesLoaded option #63

kevinzweerink opened this issue Oct 21, 2020 · 2 comments

Comments

@kevinzweerink
Copy link

Flickity's imagesLoaded option allows automatic re-rendering of the slideshow once images have fully loaded, but requires the explicit inclusion of flickity-imagesloaded, which is not currently part of this package.

As things are now, you can approximate this behavior by manually importing imagesloaded and binding it to flickity's ready event through flickityOptions like so:

<template>
  <Flickity :options='flickityOptions' ref='flickity'>
    <div v-for='image, i in images' :key='image._id'/>
      <img :src='image.url'/>
    </div>
  </Flickity> 
</template>

<script>
import imagesLoaded from 'imagesloaded';

export default {
  name: 'Slideshow',
  props: {
    images: Array
  },
  methods: {
    loadComplete () {
      if (this.$refs.flickity) {
        this.$refs.flickity.reloadCells();
      }
    }
  },
  data() {
    return {
      flickityOptions: {
        prevNextButtons: false,
        pageDots: false,
        on: {
          ready: () => { imagesLoaded(this.$refs.flickity, this.loadComplete) }
        }
      }
    }
  }
}
</script>

But it would much nicer to be able just do this and clean up the ref:

<template>
  <Flickity :options='flickityOptions'>
    <div v-for='image, i in images' :key='image._id'/>
      <img :src='image.url'/>
    </div>
  </Flickity> 
</template>

<script>
export default {
  name: 'Slideshow',
  props: {
    images: Array
  },
  data() {
    return {
      flickityOptions: {
        prevNextButtons: false,
        pageDots: false,
        imagesLoaded: true
      }
    }
  },
}
</script>
@MRloll
Copy link

MRloll commented Dec 6, 2020

This is really helpful.
thank you so much.

@FDuschicka
Copy link

works like a charm!
thank you for saving me after 4hrs without progress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants