vue-perfect-lightbox
v1.0.0
Published
A perfect image responsive lightbox component for Vuejs with zoom feature
Downloads
2
Maintainers
Readme
vue-perfect-lightbox
A perfect image responsive lightbox component for Vuejs with zoom feature Thanks to pexea12
Development (NPM / Yarn)
npm run dev
yarn dev
Install
NPM / Yarn
Install the package:
npm install vue-perfect-lightbox vue-lazyload
yarn add vue-perfect-lightbox vue-lazyload
Globally in your project (main.js)
import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'
import PerfectLightBox from 'vue-perfect-lightbox'
Vue.use(VueLazyLoad)
Vue.use(PerfectLightBox)
Inside component
import LightBox from 'vue-perfect-lightbox'
export default {
components: {
LightBox
},
}
plugins/vue-perfect-lightbox.js for Nuxt Js
import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'
import PerfectLightBox from 'vue-perfect-lightbox'
require('vue-perfect-lightbox/dist/vue-perfect-lightbox.min.css')
Vue.use(VueLazyLoad)
Vue.use(PerfectLightBox)
Inside nuxt.config.js add the plugin
{ src: '~/plugins/vue-perfect-lightbox.js', mode: 'client'},
Import CSS style
require('vue-perfect-lightbox/dist/vue-perfect-lightbox.min.css')
// Use only when you are using Webpack
How to use:
<light-box :media="media"></light-box>
How to use for Nuxt Js:
<client-only>
<light-box :media="media"></light-box>
</client-only>
media
has the structure:
[
{ // For image
thumb: 'http://example.com/thumb-image1.jpg',
src: 'http://example.com/image1.jpg',
caption: 'caption to display. receive <html> <b>tag</b>', // Optional
srcset: '...' // Optional for displaying responsive images
},
{ // For image
thumb: 'http://example.com/thumb-image2.jpg',
src: 'http://example.com/image2.jpg',
caption: 'caption to display. receive <html> <b>tag</b>', // Optional
srcset: '...' // Optional for displaying responsive images
},
]
Options
Properties
Methods
Slots
close
The content of the close button.
footer
The content of the footer under the image.
slot-scopes
previous
The previous button on the main image.
next
The next button on the main image.
previousThumb
The previous button on the thumbs list.
nextThumb
The next button on the thumbs list.
customCaption
The caption of the current image.
videoIcon
The Icon used for videos
Events
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 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.onImageChanged
: Emit when the image is changed.
CREDITS
Most of the code belongs to pexea12