Vue Bootstrap LightBox MDB Pro component
Vue Lightbox - Bootstrap 4 & Material Design
Note: We are transitioning MDB4 to a legacy version and focusing on developing MDB5.
While we'll continue to support for the transition period, we encourage you to migrate to
MDB5. We're offering a 50% discount on MDB5 PRO to help with your transition,
enabling you to leverage the full potential of the latest version. You can find more information here.
get 50% discount on MDB5 PRO
Vue Bootstrap lightbox is a group of images combined in one responsive gallery. Elements are grouped in thumbnail grid, which can be displayed as a slideshow.
Vue live previewThe mdbLightbox component uses touch events on mobile screens. Add add the following
import statement in your main.js
file:
import Vue2TouchEvents from 'vue2-touch-events';
Vue.use(Vue2TouchEvents);
Basic example
A basic example of a lightbox with the most common use case with the bootstrap grid.
<template>
<mdb-lightbox :imgs="imgs" gallery></mdb-lightbox>
</template>
<script>
import {
mdbLightbox
} from 'mdbvue';
export default {
components: {
mdbLightbox
},
data() {
return {
imgs: [
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(117).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(98).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(131).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(123).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(118).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(128).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(132).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(115).webp',
'https://mdbootstrap.com/img/Photos/Horizontal/Nature/12-col/img%20(133).webp'
],
};
}
}
</script>
Gallery with margins
Add gap
property to your lightbox
<template>
<mdb-lightbox :imgs="gallery" gallery gap></mdb-lightbox>
</template>
<script>
import {
mdbLightbox,
mdbContainer,
mdbRow,
mdbCol
} from 'mdbvue';
export default {
components: {
mdbLightbox,
mdbContainer,
mdbRow,
mdbCol
},
data() {
return {
gallery: [{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(145).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(145).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(150).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(150).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(152).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(152).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(42).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(42).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(151).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(151).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(40).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(40).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(148).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(148).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(147).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(147).webp'
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(146).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(146).webp',
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(149).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(149).webp',
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(41).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(41).webp',
},
{
thumbnail: 'https://mdbootstrap.com/img/Photos/Lightbox/Thumbnail/img%20(43).webp',
img: 'https://mdbootstrap.com/img/Photos/Lightbox/Original/img%20(43).webp',
}
],
};
}
}
</script>
Gallery with heading
An example of a lighbox used in a gallery together with heading.
<template>
<mdb-container>
<h2 class="font-weight-bold my-5 text-center">My Projects</h2>
<mdb-lightbox :imgs="imgs" gallery gap imgClass="z-depth-1"></mdb-lightbox>
</mdb-container>
</template>
<script>
import {
mdbLightbox,
mdbContainer
} from 'mdbvue';
export default {
components: {
mdbLightbox,
mdbContainer,
},
data() {
return {
imgs: [{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(63).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(63).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(66).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(66).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(65).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(65).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(67).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(67).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(68).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(68).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(64).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(64).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(69).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(69).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(59).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(59).webp"
},
{
thumbnail: "https://mdbootstrap.com/img/Mockups/Lightbox/Thumbnail/img%20(70).webp",
img: "https://mdbootstrap.com/img/Mockups/Lightbox/Original/img%20(70).webp"
}
],
};
},
}
</script>
LVue Lightbox - API
In this section you will find advanced information about the Lightbox component. You will learn which modules are required in this component, what are the possibilities of configuring the component, and what events and methods you can use in working with it.
Import statement
<script>
import {
mdbLightbox
} from 'mdbvue';
</script>
API Reference: Properties
Name | Type | Default | Description | Example |
---|---|---|---|---|
imgs |
Array |
|
An array of objects (data structure below) or strings (full-size images to open after lightbox launch - old syntax) | <mdb-lightbox :imgs="imgs" gallery/> |
gallery |
Boolean | false |
If set to true, component will render a gallery of all images as well (basing on the thumbnail value) | <mdb-lightbox :imgs="imgs" gallery/> |
columns |
Number | 3 |
Changes the number of columns in the gallery | <mdb-lightbox :imgs="imgs" gallery :columns="4"/> |
gap |
Boolean | false |
Adds a gap between images in the gallery | <mdb-lightbox :imgs="imgs" gallery gap/> |
imgClass |
String |
|
Adds a class to the images in the gallery | <mdb-lightbox :imgs="imgs" gallery imgClass="z-index-1"/> |
imgs |
Array | {} |
An array of objects (data structure below ) of strings (full-size images to open after lightbox launch) | <mdb-lightbox :imgs="imgs"/> |
index (old syntax) |
Number | 0 |
Index of element, which has to be opened | <mdb-lightbox :imgs="imgs" :index="index" /> |
visible (old syntax) |
Boolean | false |
Determines whether to open the lightbox | <mdb-lightbox :visible="true" ... /> |
captions (old syntax) |
Array |
|
An array of captions corresponding to images at the same index. | <mdb-lightbox :captions="['title1', 'title2']" /> |
Data structure
const imgs = [
{
img: "Image's source (fullsize)",
thumbnail: "Image's source (minature)",
caption: "Image's caption"
}
]
API Reference: Methods
Name | Parameters | Description | Example |
---|---|---|---|
@hide |
Evokes afeter closing the lightbox | <mdb-lightbox @hide="handleHide" ... /> |