Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify carousel image loading

I want to use the vuetify's carousel to display some images. But on the first sliding, there is a white flash while transitioning, like the image was not loaded until it tries to render it.

<div id="app">
  <v-app id="inspire">
    <v-carousel>
      <v-carousel-item
        v-for="(item,i) in items"
        :key="i"
        :src="item.src"
      ></v-carousel-item>
    </v-carousel>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      items: [
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg',
        },
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/planet.jpg',
        },
      ],
    }
  },
})

Demo where you can see what i'm talking about : https://codepen.io/gaalee89/pen/RwPQWXj

Is there a way to fixe this ? Thanks.

like image 897
gaalee Avatar asked Mar 11 '20 02:03

gaalee


1 Answers

I found that the eager attribute is part of the solution, but not the whole solution, as it only seems to apply to nested content. Nest a v-img tag inside v-carousel-item with the eager attribute on both, then all images will preload.

<div id="app">
  <v-app id="inspire">
    <v-carousel>
      <v-carousel-item
        v-for="(item,i) in items"
        :key="i"
        eager
      >
        <v-img :src="item.src" height="100%" eager/>
      </v-carousel-item>
    </v-carousel>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
    return {
      items: [
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/bird.jpg',
        },
        {
          src: 'https://cdn.vuetifyjs.com/images/carousel/planet.jpg',
        },
      ],
    }
  },
})

Then you need need to adjust the layout, as the image content will behave differently. height="100%" on the v-img worked for me.

like image 120
Alex Robinson Avatar answered Oct 21 '22 10:10

Alex Robinson