Install vue-it-bigger via npm
masterInstall the package using npm to add the lightbox component to your Vue 3 project.
npm install vue-it-biggerrepository·master·Indexed 41 days ago
https://github.com/haiafara/vue-it-biggerA simple, unobtrusive image and YouTube video lightbox component for Vue 3. Version 1.2.1 supports image, youtube, and HTML5 video types via a media array prop, providing customizable UI through slots like customCaption and imageOverlay.
Install the package using npm to add the lightbox component to your Vue 3 project.
npm install vue-it-biggerTo use the component, import LightBox and its corresponding CSS file in your script section, register it as a component, and pass a media array to the template.
import LightBox from 'vue-it-bigger'
import 'vue-it-bigger/dist/vue-it-bigger.css'
export default {
components: {
LightBox,
},
}<LightBox :media="media"></LightBox>Use the following properties to customize the behavior and appearance of the lightbox:
| name | type | default | description |
|------|------|---------|-------------|
| media | Array | required | Media array to display |
| showLightBox | Boolean | true | Whether to show lightbox or not at the beginning |
| startAt | Number | 0 | Index of the image that you want to start at |
| nThumbs | Number | 7 | Number of thumbnail images |
| showThumbs | Boolean | true | Whether to show thumbnails or not |
| autoPlay | Boolean | false | Move to next image automatically |
| autoPlayTime | Number | 3000 (ms) | Time to stop at an image before move on to next image |
| interfaceHideTime | Number | 3000 (ms) | Time after which the interface is hidden |
| showCaption | Boolean | false | Whether to show caption or not |
| disableScroll | Boolean | true | set to `true` to avoid scrolling views behind lightbox |
| lengthToLoadMore | Number | 0 | Minimum length unto end to emit load more event |
| closable | Boolean | true | Display the close button at the right top corner or not. ESC clicking-close will also be disabled if closable is set to false. |
| closeText | String | Close (Esc) | Text for the close button |
| previousText | String | Previous | Text for the previous image button |
| nextText | String | Next | Text for the next image button |The imageOverlay slot allows you to render content (like annotations) directly on top of the current image. This slot is only available for image slides; it is skipped for video and YouTube slides. Pointer events are off by default.
<LightBox
ref="overlayLightbox"
:media="media"
>
<template v-slot:imageOverlay="{ currentMedia }">
<MyAnnotationsOverlay :annotations="currentMedia.annotations" />
</template>
</LightBox>The customCaption slot allows you to completely control how the caption is rendered, providing access to the currentMedia object.
<LightBox
ref="customCaptionLightbox"
:media="media"
:show-caption="true"
>
<template v-slot:customCaption="slotProps">
{{ slotProps.currentMedia.caption }}<br>
There could be some description here.
</template>
</LightBox>The component emits several events during its lifecycle:
- `onOpened`: Emit when the lightbox is opened.
- `onClosed`: Emit when the lightbox is closed.
- `onLastIndex`: Emit when the current image is the last one of the list.
- `onFirstIndex`: Emit when the current image is the first one of the list.
- `onStartIndex`: Emit when the current image is at the `startAt` index.
- `onLoad`: Emit when there are `lengthToLoadMore` images left in the array.You can interact with the lightbox programmatically using a component ref to call these methods:
| name | arguments | description |
|------|-----------|-------------|
| nextImage | () | Move to next image |
| previousImage | () | Move to previous image |
| closeLightBox | () | Close lightbox |
| showImage | (index) | Show the image at index |Use slots to override default UI elements. Some slots provide data via slotProps.
| Slot | Description | Slot Props |
|------|-------------|------------|
| close | The content of the close button | None |
| footer | The content of the footer under the image | `current` (integer), `total` (integer) |
| previous | The previous button on the main image | None |
| next | The next button on the main image | None |
| customCaption | The caption of the current image | `currentMedia` (Object) |
| imageOverlay | Content rendered on top of the image (images only) | `currentMedia` (Object), `index` (integer) |
| videoIcon | The Icon used for videos | None |The media prop accepts an array of objects. Supported types are image (default), youtube, and video (for HTML5 <video> tags).
[
{ // For an image
type: 'image', // Can be omitted for image
thumb: 'http://example.com/thumb.jpg',
src: 'http://example.com/image.jpg',
caption: 'Caption to display. HTML <b>enabled</b>',
srcset: '...'
},
{ // For a YouTube video
type: 'youtube',
thumb: 'https://img.youtube.com/vi/WsptdUFthWI/hqdefault.jpg',
id: 'WsptdUFthWI',
caption: 'HTML <b>enabled</b> caption to display'
},
{ // For a video that can be played in the <video> tag
type: 'video',
thumb: 'https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider2.jpg',
sources: [
{
src: 'https://www.w3schools.com/html/mov_bbb.mp4',
type: 'video/mp4'
}
],
caption: '<h4 class="Monsters Inc."></h4>',
width: 800, // Required
height: 600, // Required
autoplay: true
}
]The vue-it-bigger package provides a LightBox component as its default export. To use it in a Vue 3 application, import the package and register the component globally or locally. The package also automatically imports its required CSS styles.
import LightBox from 'vue-it-bigger';
// In your Vue app
const app = createApp(App);
app.component('LightBox', LightBox);
app.mount('#app');