vue-it-bigger-vladfork
v0.1.12
Published
A simple image / video lightbox component for Vue.js. Based on vue-it-bigger.
Downloads
2
Maintainers
Readme
FORK of Vue It Bigger!
A simple image / video lightbox component for Vue.js. Forked from vue-it-bigger.
This version is also using vue-pinch-zoom
Click on the screenshot above for a demo.
Why I bother to fork it?:
- Parameter
show-light-box
is now reactive, whitch is easier to toggle LightBox from parent - Parameter
start-at
is reactive as well - Pinch to zoom added, which is useful for mobile view
- Lazy-load added. Currently with default image only
Features
- NEW: pinch to zoom
- NEW: lazy-loader
- Unobtrusive interface that disappears after a few seconds, reappears on mouse activity
- Optional thumbnail strip with all of the gallery's media
- Can show an HTML enabled caption under each image or video
- Can play the slideshow automatically
- All of the graphics (previous, next and close buttons) can be customized via slots
- Can skip to next / previous media programatically
Improvements over vue-image-lightbox
- Lightbox opens and closes with a short fade
- Media's width is no longer limited (stretches to the full width / height of the window)
- When opening the lightbox the media doesn't flicker
- Moved caption bar and image counter off the media to the bottom of the screen
- Moved thumbnails to the top of the screen (as the bottom is now used by the caption bar)
- All interface elements have a background for better visibility
- Simplified CSS
Installation
You know the drill:
npm install vue-it-bigger-vladfork
yarn add vue-it-bigger-vladfork
Usage
You can view App.vue or the demo for an usage example.
In the <script>
section of your component import it:
import LightBox from "vue-it-bigger-vladfork";
import("vue-it-bigger-vladfork/dist/vue-it-bigger-vladfork.min.css"); // when using webpack
Add it to the list of used components:
export default {
components: {
LightBox
}
};
And use it in the <template>
section:
<LightBox
:media="media"
:show-light-box="showLightBox"
:start-at="lbStartAt"
@toggleLightBox="toggleLightBox"
></LightBox>
The media
prop has the following structure
[
{
// For an image
thumb: "http://example.com/thumb.jpg",
src: "http://example.com/image.jpg",
caption: "Caption to display. HTML <b>enabled</b>", // Optional
srcset: "..." // Optional for displaying responsive images
},
{
// For a 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"
}
],
type: "video",
caption: "<h4>Monsters Inc.</h4>",
width: 800, // Required
height: 600, // Required
autoplay: true // Optional: Autoplay video when the lightbox opens
}
];
data
variables:
data () {
return {
media: [
...
]
showLightBox: false,
lbStartAt: 0,
...
}
},
add toggle method to methods
:
toggleLightBox(v) {
this.showLightBox = v || false
},
to show the LightBox use a method
something like:
openGallery(index) {
this.lbStartAt = index || 0
this.showLightBox = true
}
Where index
is the Index of image you want to pop up
Using it with NuxtJs
Create a file named lightbox.js
under the plugins
directory with following contents:
import Vue from "vue";
import LightBox from "vue-it-bigger-vladfork";
import("vue-it-bigger-vladfork/dist/vue-it-bigger-vladfork.min.css");
const plugin = {
install() {
Vue.component("LightBox", LightBox);
}
};
Vue.use(plugin);
Add the plugin in nuxt.config.js
:
plugins: [
{
src: "~/plugins/lightbox.js",
ssr: false
}
];
Use it in any of your components:
<no-ssr placeholder="Loading...">
<!-- this component will only be rendered on client-side -->
<LightBox :media="lightBoxMedia" ....></LightBox>
</no-ssr>
Options
Properties
Methods
Slots
close
The content of the close button.
footer
The content of the footer under the image.
Slot props
previous
The previous button on the main image.
next
The next button on the main image.
customCaption
The caption of the current image.
Slot props
Usage example:
<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>
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.
Development (NPM / Yarn)
Clone the repository, cd into it and run:
npm run dev
yarn dev
After you add or modify something make sure the tests still pass:
npm run test
yarn test
ToDo
- Improve documentation
- Add pinch to zoom options
Credits
- Original CSS was based on react-images
- vue-image-lightbox authored by @pexea12
- Other contributors
License
This project is licensed under the the Apache License, Version 2.0.