A simple image lightbox component for Vuejs
NPM Package
I use CSS style from react-images
npm run dev
yarn dev
Install the package:
npm install vue-image-lightbox vue-lazyload
yarn add vue-image-lightbox vue-lazyload
Then import it in your project
At your entry point (main.js
normally)
import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'
...
Vue.use(VueLazyLoad)
and use the lightbox:
import LightBox from 'vue-image-lightbox'
export default {
components: {
LightBox,
},
}
<script src="path/to/vue.js"></script>
<script src="path/to/dist/vue-image-lightbox.js"></script>
You can simply view App.vue to see how to use vue-image-lightbox
Import CSS style
require('vue-image-lightbox/dist/vue-image-lightbox.min.css')
// Use only when you are using Webpack
How to use:
<LightBox :images="images"></LightBox>
images
has the structure:
[
{
thumb: 'http://example.com/thumb.jpg',
src: 'http://example.com/image.jpg',
caption: 'caption to display. receive <html> <b>tag</b>', // Optional
srcset: '...' // Optional for displaying responsive images
}
]
name | type | default | description |
---|---|---|---|
images | Array | required | Image 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 |
siteLoading | null | default image when your image is error or loading | |
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 |
name | arguments | description |
---|---|---|
nextImage | () | Move to next image |
previousImage | () | Move to previous image |
closeLightBox | () | Close lightbox |
showImage | (index) | Show the image at index |
onOpened(value)
:true
to emit when the lightbox is opened andfalse
when it 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 thestartAt
index (specified in the properties).onLoad
: Emit when there arelengthToLoadMore
images left in the array (specified in the properties). For example, iflengthToLoadMore = 2
and there are 7 images in your array, when you reach index 4 (which means there are 2 images left which are not discovered yet), this event will be emitted. After that, if the image array are updated and there are totally 15 images, the event will be emitted at index 12.
Most of the CSS belongs to react-images