Load webp format image in Vue Carousel component
19 Jul 20246 minutes to read
You can load the carousel image in the webp format, which aims to create smaller, better-looking images. Choosing webp as your image format can significantly improve your website’s performance without sacrificing visual quality. webp images are significantly smaller in file size compared to formats like JPEG and PNG. This results in faster load times and less data usage. To achieve this, you can convert your image format to webp and pass them to Carousel items. The following sample illustrates how to load a carousel image in the webp format component.
<template>
<div class="control-container">
<ejs-carousel animationEffect='Fade'>
<e-carousel-items>
<e-carousel-item template="Cardinal"></e-carousel-item>
<template v-slot:Cardinal>
<figure class="img-container">
<img src="https://www.gstatic.com/webp/gallery/1.webp" alt="Majestic Valley View" style="height:100%;width:100%;" />
<figcaption class="img-caption">Majestic Valley View</figcaption>
</figure>
</template>
<e-carousel-item template="kingfisher"></e-carousel-item>
<template v-slot:kingfisher>
<figure class="img-container">
<img src="https://www.gstatic.com/webp/gallery/2.webp" alt="Thrilling Rapids Adventure" style="height:100%;width:100%;" />
<figcaption class="img-caption">Thrilling Rapids Adventure</figcaption>
</figure>
</template>
<e-carousel-item template="keel-billed-toucan"></e-carousel-item>
<template v-slot:keel-billed-toucan>
<figure class="img-container">
<img src="https://www.gstatic.com/webp/gallery/3.webp" alt="Snowy Stroll" style="height:100%;width:100%;" />
<figcaption class="img-caption">Snowy Stroll</figcaption>
</figure>
</template>
</e-carousel-items>
</ejs-carousel>
</div>
</template>
<script setup>
import { CarouselComponent as EjsCarousel, CarouselItemsDirective as ECarouselItems, CarouselItemDirective as ECarouselItem } from '@syncfusion/ej2-vue-navigations';
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
.control-container {
height: 360px;
margin: 0 auto;
width: 600px;
}
.img-container {
height: 100%;
margin: 0;
}
.img-caption {
color: #fff;
font-size: 1rem;
position: absolute;
bottom: 3rem;
width: 100%;
text-align: center;
}
</style><template>
<div class="control-container">
<ejs-carousel animationEffect='Fade'>
<e-carousel-items>
<e-carousel-item template="Cardinal"></e-carousel-item>
<template v-slot:Cardinal>
<figure class="img-container">
<img src="https://www.gstatic.com/webp/gallery/1.webp" alt="Majestic Valley View" style="height:100%;width:100%;" />
<figcaption class="img-caption">Majestic Valley View</figcaption>
</figure>
</template>
<e-carousel-item template="kingfisher"></e-carousel-item>
<template v-slot:kingfisher>
<figure class="img-container">
<img src="https://www.gstatic.com/webp/gallery/2.webp" alt="Thrilling Rapids Adventure" style="height:100%;width:100%;" />
<figcaption class="img-caption">Thrilling Rapids Adventure</figcaption>
</figure>
</template>
<e-carousel-item template="keel-billed-toucan"></e-carousel-item>
<template v-slot:keel-billed-toucan>
<figure class="img-container">
<img src="https://www.gstatic.com/webp/gallery/3.webp" alt="Snowy Stroll" style="height:100%;width:100%;" />
<figcaption class="img-caption">Snowy Stroll</figcaption>
</figure>
</template>
</e-carousel-items>
</ejs-carousel>
</div>
</template>
<script>
import { CarouselComponent, CarouselItemDirective, CarouselItemsDirective } from "@syncfusion/ej2-vue-navigations";
export default {
name: "App",
components: {
"ejs-carousel": CarouselComponent,
"e-carousel-items": CarouselItemsDirective,
"e-carousel-item": CarouselItemDirective
}
};
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material.css";
.control-container {
height: 360px;
margin: 0 auto;
width: 600px;
}
.img-container {
height: 100%;
margin: 0;
}
.img-caption {
color: #fff;
font-size: 1rem;
position: absolute;
bottom: 3rem;
width: 100%;
text-align: center;
}
</style>