Simple lightbox plugin written in pure javascript with no dependencies
- Pure JavaScript, no dependencies
- Swipe gestures
- Minimalistic look
- Image captions
- Multiple galleries per page, each with custom options
- Responsive design
- Looks great on mobile and desktop
- Download
vanillaBox.min.css
andvanillaBox.min.js
files from thedist
folder. - Include them somewhere in your project:
<link rel="stylesheet" href="css/vanillaBox.min.css">
<script src="js/vanillaBox.min.js" async></script>
Initialize the script by running:
let el = document.getElementById("gallery");
let gallery = new VanillaBox(el);
where the first argument is an element on which the gallery will be initialized. This will initialize the gallery and by default add an event listener to all thumbnails that will open the gallery with the corresponding image. The HTML code may look like this:
<div id="gallery">
<img class="thismage" src="img/img1.jpeg" alt="Camera">
<img class="thismage" src="img/img4.jpeg" vb-data-caption="Best picture ever!">
<img class="thismage" src="img/img2.jpeg" alt="Whale">
...
</div>
To use captions put vb-data-caption
attribute on the img
tag.
You can pass an object with custom options as the second parameter.
let gallery = new VanillaBox(el, {
// User options
});
Initialize vanillaBox.js
- @param
element
{HTMLElement} - HTML element containing <img> tags - @param
options
{object} - custom options (see #Customization) - @return {object} - instance of the vanillaBox.js gallery
Show the gallery and move the gallery to a specific image
- @param
index
{number} - the position of the image, default is [0] - @return {boolean} - true on success or false if the index is invalid
Usage:
let gallery = = VanillaBox(el);
baguetteBox.open(2); //Opens gallery and shows third image
Switch to the next item in the gallery
- @return {boolean} - true on success or false if there are no more images to be loaded
Switch to the next item in the gallery
- @return {boolean} - true on success or false if there are no more images to be loaded
Sets the current item in the gallery to index.
- @return {boolean} - true on success and false if invalid index
Hides on screen controls
- @return {boolean} - toggle status, true if shown and false if hidden
Closes the gallery
Remove the plugin with any event bindings
Desktop:
- IE 11
- Chrome
- Safari
- Firefox
- Opera
Mobile:
- Chrome
- Safari
This content is released under the MIT License.
Copyright (c) 2018 rradosic