A lightbox is a small helper that shows a larger version of an image (or a video) on top of the current web page. While the larger image is visible, the rest of the page is dimmed so the user’s attention stays on the content. The technique was first made popular by Lightbox v2 and the name lightbox is now used as a generic term for any JavaScript library that offers this kind of overlay view.
lightGallery is a fast, modular and responsive JavaScript lightbox. It is well-suited for desktops, tablets and phones, supports keyboard navigation, mouse drag, touch gestures and even YouTube, Vimeo, Dailymotion, VK and HTML5 videos. Because lightGallery is modular, the core library only contains the basic gallery; every extra feature (thumbnails, zoom, full-screen, autoplay, share buttons, …) is provided by a plugin that you load only when you really need it.
lightGallery
Here’s a breakdown of the most important features:
- Image and video galleries
-
Display image galleries, single videos or mixed galleries (images and videos in the same gallery). Supports YouTube, Vimeo, Dailymotion, VK and any HTML5 video format (MP4, WebM, Ogg, …).
- Modular architecture
-
The core library is small and only handles slide navigation. All other features are loaded as plugins (
lgThumbnail,lgZoom,lgFullscreen,lgAutoplay,lgShare,lgRotate,lgHash,lgPager,lgComment,lgVideo, …). - Touch-friendly
-
Built-in support for touch gestures on mobile devices (swipe, drag). Mouse drag works the same way on desktops.
- Keyboard navigation
-
Arrow keys move between slides, Esc closes the gallery and F toggles full-screen (when the full-screen plugin is loaded).
- Responsive
-
Automatically picks the right image size based on the viewport through the standard
srcset/sizesattributes or the simplerdata-responsiveattribute. - Hardware-accelerated transitions
-
A large number of CSS3 transitions (slide, fade, zoom, scale, skew, rotate, …). All transitions are hardware-accelerated where the browser allows it.
- Customisable
-
Every visible part of the gallery can be styled through CSS or Sass variables. Most plugins also expose options to change the default behaviour without touching any code.
- Multiple instances
-
You can run as many independent galleries on the same page as you like.
The lightGallery website contains the original API documentation. The pages in this manual are not a copy of the original pages: they are restructured to match the style used in the rest of the J1 Template manuals and they describe the version of lightGallery (v2.8.3) that is shipped with the J1 Template.
| The original documentation pages are based on lightGallery version v2.8.3 for the current J1 template version 2025.x. The idea of providing this documentation is not to simply copy the original pages as duplicates. For better readability and usability, all pages are restructured and enhanced by code examples or improved description texts. The documentation pages for the J1 Template project will be used for the AI-based chat client (planned for 4th quarter of 2025). The agent will be trained by all available documentation pages of the template system to give users an easy-to-use source for using the J1 Template to create websites for their needs. |
Usage
A lightGallery instance is created by calling the global lightGallery() function with two arguments:
-
The gallery container — a DOM element that wraps all the clickable thumbnails. This is the element on which lightGallery listens for click events.
-
An options object that selects which thumbnails open the gallery (
selector) and configures every other behaviour (transition speed, plugins, captions, …).
| Name | Description |
|---|---|
| The gallery container element. Pass a real DOM element (for example obtained from |
| The clickable elements inside the gallery container. May be a CSS selector string (for example |
Initialization
A complete lightGallery setup needs the lightGallery JavaScript file (lightgallery.min.js) and the main stylesheet (lightgallery-bundle.min.css), plus one or more plugin scripts (lg-thumbnail.min.js, lg-zoom.min.js, …) for any extra features. Plugins are passed to lightGallery through the plugins option:
<!-- 1. Stylesheet (in <head>) -->
<link rel="stylesheet" href="css/lightgallery-bundle.min.css" />
<!-- 2. Core library (just before </body>) -->
<script src="js/lightgallery.min.js"></script>
<!-- 3. Plugins (just after the core library) -->
<script src="js/plugins/lg-thumbnail.min.js"></script>
<script src="js/plugins/lg-zoom.min.js"></script>
<!-- 4. Initialisation (just after the plugin scripts) -->
<script>
const galleryEl = document.getElementById('my_gallery');
const lg = lightGallery(galleryEl, {
selector: 'a',
speed: 500,
plugins: [lgThumbnail, lgZoom]
// ... other options
});
</script>HTML pattern – unordered list
The unordered-list pattern fits well into Bootstrap-based layouts because the <li> elements can carry grid classes (col-xs-6 col-sm-4 col-md-3 …) so the thumbnail grid is responsive without any extra CSS:
<!-- gallery container (required) -->
<div id="my_gallery" class="gallery-block">
<div class="title">My gallery title</div>
<!-- list of slides (required) -->
<ul class="row list-unstyled">
<!-- single slide (required) -->
<li class="col-xs-6 col-sm-4 col-md-3"
data-src="path/to/large_1.jpg"
data-sub-html="<h4>Caption: image 1</h4>">
<a href="#">
<img class="img-fluid" src="path/to/thumb_1.jpg" alt="Image 1" />
</a>
</li>
<!-- more slides ... -->
<li class="col-xs-6 col-sm-4 col-md-3"
data-src="path/to/large_n.jpg"
data-sub-html="<h4>Caption: image n</h4>">
<a href="#">
<img class="img-fluid" src="path/to/thumb_n.jpg" alt="Image n" />
</a>
</li>
</ul>
</div>HTML pattern – anchor tags
For galleries that do not need a Bootstrap-style responsive grid, the simpler anchor-tag pattern is easier to read. Each <a> element is a slide and its href attribute holds the URL of the large image (no data-src is needed in this case):
<div id="my_gallery" class="gallery-container">
<a href="path/to/large_1.jpg"
data-sub-html="<h4>Caption: image 1</h4>">
<img src="path/to/thumb_1.jpg" alt="Image 1" />
</a>
<a href="path/to/large_2.jpg"
data-sub-html="<h4>Caption: image 2</h4>">
<img src="path/to/thumb_2.jpg" alt="Image 2" />
</a>
<!-- more slides ... -->
</div>
<script>
const galleryEl = document.getElementById('my_gallery');
lightGallery(galleryEl, { selector: 'a' });
</script>Dynamic mode
Dynamic mode lets you open lightGallery without any thumbnail HTML on the page. Instead of reading the slides from the DOM, the gallery is built from a JavaScript array passed through the dynamicEl option. This is useful when the slides come from an API or are generated on the fly.
To use dynamic mode, set dynamic: true and provide the slide list through dynamicEl. After initialisation, call openGallery() on the returned instance to actually show the gallery (lightGallery will not open by itself in dynamic mode, because there are no thumbnails to click on):
const dynamicGallery = lightGallery(document.getElementById('open-btn'), {
dynamic: true,
dynamicEl: [
{
src: 'path/to/image_1.jpg',
thumb: 'path/to/thumb_1.jpg',
subHtml: '<h4>Image 1</h4><p>First image of the gallery.</p>'
},
{
src: 'path/to/image_2.jpg',
thumb: 'path/to/thumb_2.jpg',
subHtml: '<h4>Image 2</h4><p>Second image of the gallery.</p>'
}
// ... more slides
],
plugins: [lgThumbnail, lgZoom]
});
// open the gallery on the second slide (index = 1)
document.getElementById('open-btn').addEventListener('click', () => {
dynamicGallery.openGallery(1);
});Translating
lightGallery shows a number of short text fragments in its UI (button tool-tips and error messages). All of them are stored in the strings option of the core, plus one *PluginStrings option per plugin. You can translate any string by overriding the matching key:
const lg = lightGallery(galleryEl, {
selector: 'a',
speed: 500,
plugins: [lgThumbnail, lgZoom, lgFullscreen, lgAutoplay, lgRotate, lgShare],
// Core strings (always present)
strings: {
closeGallery: 'Close gallery',
toggleMaximize: 'Toggle maximize',
previousSlide: 'Previous slide',
nextSlide: 'Next slide',
download: 'Download',
playVideo: 'Play video',
mediaLoadingFailed: 'Oops... Failed to load content...'
},
// Plugin-specific strings (only used if the matching plugin is loaded)
thumbnailPluginStrings: { toggleThumbnails: 'Toggle thumbnails' },
zoomPluginStrings: { zoomIn: 'Zoom in',
zoomOut: 'Zoom out',
viewActualSize: 'View actual size' },
fullscreenPluginStrings: { toggleFullscreen: 'Toggle Fullscreen' },
autoplayPluginStrings: { toggleAutoplay: 'Toggle Autoplay' },
rotatePluginStrings: { flipVertical: 'Flip vertical',
flipHorizontal: 'Flip horizontal',
rotateLeft: 'Rotate left',
rotateRight: 'Rotate right' },
sharePluginStrings: { share: 'Share' }
});Mobile settings
On small screens it is often useful to hide some of the controls (close button, download button, navigation arrows …) to keep the interface clean. lightGallery makes this easy through the mobileSettings option: any value placed there overrides the matching core setting when the gallery is opened on a touch device.
The default mobileSettings are:
mobileSettings: {
controls: false, // hide previous / next arrows
showCloseIcon: false, // hide the close icon (swipe-to-close still works)
download: false // hide the download button
}You can override or extend the defaults like this:
const lg = lightGallery(galleryEl, {
selector: 'a',
// every value below is only used on mobile devices
mobileSettings: {
controls: true,
download: false,
rotate: false,
showCloseIcon: true
}
});J1 Integration
J1 Theme ships with a full integration of lightGallery. For most galleries no manual configuration and no extra HTML is required: J1 generates the gallery markup and calls lightGallery() for you, based on a single YAML configuration file (j1_lightgallery_mgr.yml) that lists the gallery items and the plugin set you want to load.
The information in this section is only relevant if you want to extend the default integration – for example, to write your own plugin or to change the look of the gallery through Sass variables. For day-to-day usage, the YAML configuration is enough.
Plugin API
A plugin is a JavaScript class that adds extra features to the lightGallery core. The class only has to expose two methods: init(), which is called when the gallery is built, and destroy(), which is called when the gallery is taken down again.
The plugin receives the core lightGallery instance as the first argument of its constructor; from there it can read the user-supplied settings (this.core.settings), listen to gallery events (this.core.LGel.on(…)) and add buttons to the toolbar (this.core.$toolbar.append(…)).
The skeleton of a custom plugin looks like this:
class MyPlugin {
// 1. The constructor receives the lightGallery core instance.
constructor(instance) {
this.core = instance;
// 2. Read user options (and provide default values).
this.settings = Object.assign(
{ myOption: true }, // defaults
this.core.settings // user-supplied options
);
return this;
}
// 3. init() is called once when the gallery is built.
init() {
if (!this.settings.myOption) {
return;
}
// ... add UI, listen to events, etc.
}
// 4. destroy() is called when the gallery is destroyed.
destroy() {
// ... remove UI, detach listeners, etc.
}
}
// 5. Pass the plugin to the core via the `plugins` option.
const lg = lightGallery(document.getElementById('my_gallery'), {
selector: 'a',
plugins: [MyPlugin],
myOption: true
});Sass variables
The table below lists the most useful Sass variables. They are declared in the lightGallery source files and can be overridden in a custom Sass file before the lightGallery stylesheets are imported.
| Name | Default | Description |
|---|---|---|
|
| Opacity of the dark background that covers the page while the gallery is open. A value of |
|
| Background colour of the top toolbar. |
|
| Base border radius applied to gallery elements such as the toolbar buttons. |
|
| Colour used for highlighted parts of the gallery (active progress bar, active thumbnail border, …). |
|
| Background colour for icon buttons. |
|
| Default icon colour. |
|
| Icon colour on mouse hover. |
|
| Slide-counter font colour. |
|
| Slide-counter font size. |
|
| Background colour of the previous / next arrows. |
|
| Icon colour of the previous / next arrows. |
|
| Icon colour of the previous / next arrows on mouse hover. |
|
| Background colour of the autoplay progress bar. |
|
| Highlight colour of the autoplay progress bar. |
|
| Height of the autoplay progress bar. |
|
| Length of the zoom-in / zoom-out animation. |
|
| Background colour of the caption ( |
|
| Caption ( |
|
| Background colour of the toggle thumbnails button. |
|
| Icon colour of the toggle thumbnails button. |
|
| Icon colour of the toggle thumbnails button on mouse hover. |
|
| Background colour of the thumbnail strip. |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
|
| Stacking order ( |
lightGallery API
lightGallery is a fast, modular and responsive JavaScript lightbox. The core library handles slide navigation, animations and the basic toolbar. Every extra feature (thumbnails, zoom, full-screen, autoplay, …) is provided by a plugin that can be loaded independently.
This chapter documents the API of lightGallery v2.8.3 (the version shipped with the J1 template). For each option you will find its type, its default value and a short description. The longer settings also come with a small example.
Initialization
The initialisation of lightGallery happens in four steps: load the CSS (1), load the JavaScript (2), place the gallery markup in the HTML body (3) and finally call the global lightGallery() function to wire everything together (4).
CSS load
Add the lightGallery bundle stylesheet inside the <head> of the document. The bundle file already contains every plugin stylesheet, so only one <link> tag is needed:
<head>
<link rel="stylesheet" type="text/css"
href="css/lightgallery-bundle.min.css" />
</head>JS load
Include the lightGallery core script and the plugin scripts you want to use, just before the closing </body> tag. The order matters – plugins must be loaded after the core:
<body>
...
<!-- 1. lightGallery core -->
<script src="js/lightgallery.min.js"></script>
<!-- 2. Plugins (load only the ones you need) -->
<script src="js/plugins/lg-thumbnail.min.js"></script>
<script src="js/plugins/lg-zoom.min.js"></script>
<script src="js/plugins/lg-fullscreen.min.js"></script>
<script src="js/plugins/lg-autoplay.min.js"></script>
<script src="js/plugins/lg-share.min.js"></script>
<script src="js/plugins/lg-rotate.min.js"></script>
<script src="js/plugins/lg-hash.min.js"></script>
<script src="js/plugins/lg-pager.min.js"></script>
<script src="js/plugins/lg-video.min.js"></script>
...
</body>HTML markup
lightGallery accepts almost any HTML structure. The only requirement is a gallery container that wraps every clickable slide.
<a id="my_gallery" href="img/img1.jpg">
<img src="img/thumb1.jpg" alt="Image 1" />
</a>
<script>
const el = document.getElementById('my_gallery');
lightGallery(el, { selector: 'this' });
</script><a> tags as slides<div id="my_gallery">
<a href="img/img1.jpg"><img src="img/thumb1.jpg" /></a>
<a href="img/img2.jpg"><img src="img/thumb2.jpg" /></a>
</div>
<script>
const el = document.getElementById('my_gallery');
lightGallery(el, { selector: 'a' });
</script><div> tags as slides<div id="my_gallery">
<div class="item" data-src="img/img1.jpg">
<img src="img/thumb1.jpg" />
</div>
<div class="item" data-src="img/img2.jpg">
<img src="img/thumb2.jpg" />
</div>
</div>
<script>
const el = document.getElementById('my_gallery');
lightGallery(el, { selector: '.item' });
</script><ul> / <li> (J1 default)<ul id="my_gallery">
<li data-src="img/img1.jpg">
<img src="img/thumb1.jpg" />
</li>
<li data-src="img/img2.jpg">
<img src="img/thumb2.jpg" />
</li>
</ul>
<script>
const el = document.getElementById('my_gallery');
lightGallery(el, { selector: 'li' });
</script>For J1 Template, a Bootstrap-based notation built on top of (unstyled) unordered lists is used. Each image is one <li> element with grid classes such as col-xs-6 col-sm-4 col-md-3 so the thumbnails are responsive (2 / 3 / 4 columns depending on the viewport size):
<!-- gallery container (id = "j1-lightgallery") -->
<div id="j1-lightgallery" class="j1-lg-galleryblock">
<div class="title">My gallery title</div>
<!-- slide list (id = "j1-lightgallery-ul") -->
<ul id="j1-lightgallery-ul" class="row list-unstyled">
<!-- one slide per <li> – 2/3/4 per row depending on viewport -->
<li class="col-xs-6 col-sm-4 col-md-3"
data-src="/assets/image/img_1.jpg"
data-sub-html="<p>Caption text for img_1</p>">
<a href="#">
<img class="lg-thumbnail" src="/assets/image/thumb_1.jpg" />
</a>
</li>
<!-- as many slides as needed ... -->
<li class="col-xs-6 col-sm-4 col-md-3"
data-src="/assets/image/img_n.jpg"
data-sub-html="<p>Caption text for img_n</p>">
<a href="#">
<img class="lg-thumbnail" src="/assets/image/thumb_n.jpg" />
</a>
</li>
</ul>
</div>JS initialization
Once the markup is in place, call the global lightGallery() function with the gallery container element and an options object:
const galleryEl = document.getElementById('j1-lightgallery-ul');
const lg = lightGallery(galleryEl, {
selector: 'li',
mode: 'lg-fade',
speed: 500,
plugins: [lgThumbnail, lgZoom],
// ... more options
});Core options
The table below lists the options of the lightGallery core. Each plugin adds further options of its own; those are documented in the Plugins section further down.
| Name | Type | Default | Description | ||
|---|---|---|---|---|---|
| string |
| Type of transition between slides. lightGallery comes with many transitions; see chapter Transition styles for the full list. | ||
| string |
| CSS easing function used for the slide transition. Any valid | ||
| number (ms) |
| Slide transition duration in milliseconds. | ||
| string |
| lightGallery commercial license key. Leave the default value for non-commercial use; otherwise enter the key you received from the lightGallery author. | ||
| string |
| Height of the gallery wrapper. Examples: | ||
| string |
| Width of the gallery wrapper. Examples: | ||
| string |
| Custom CSS class added to the gallery wrapper. Useful when you want to apply different styles to different galleries on the same page. | ||
| string |
| Animation class used while the gallery is opening. | ||
| number (ms) |
| Length of the backdrop fade-in / fade-out animation.
| ||
| string | function | element |
| Element that the gallery is appended to. By default the gallery is attached to the body of the document. Pass a CSS selector, a DOM element or a function returning either of the two if you want to attach the gallery somewhere else. | ||
| number (ms) |
| Length of the start animation that lifts the clicked thumbnail to the position of the full-size slide. | ||
| boolean |
| If | ||
| number (ms) |
| Delay (in milliseconds) after which the gallery toolbars are hidden when the cursor is idle. A value of | ||
| number (ms) |
| How long the toolbars are kept visible right after the gallery has opened, regardless of | ||
| number (ms) |
| Delay before a slide change starts. Useful for syncing the slide transition with another animation. | ||
| boolean |
| Add fall-backs for older browsers (IE10/11, old mobile browsers). Disable for a slightly smaller runtime when you only target modern browsers. | ||
| boolean |
| If | ||
| string |
| Maximum dimensions used when displaying videos, in the form | ||
| boolean |
| Automatically load the YouTube poster image as the placeholder for YouTube video slides. | ||
| number (px) |
| Default caption height (in pixels) used while the gallery is calculating its layout. Set to a non-zero value when captions take a visible amount of vertical space, to avoid a small layout jump on opening. | ||
| string |
|
| ||
| string |
|
| ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| boolean |
| If | ||
| string |
| CSS selector that points to the element where the caption (sub-html) is appended. Use | ||
| boolean |
| If | ||
| number |
| Number of slides to preload in the background. With the default of | ||
| number |
| Maximum number of slide elements that are kept in the DOM at the same time. Increasing this value uses more memory; decreasing it forces the gallery to re-create slide elements more often. | ||
| string |
| CSS selector for the clickable slides. Pass | ||
| string | element |
| By default, lightGallery looks for slides inside the gallery container. Use this option to point to another element to look for slides in. | ||
| string |
| Custom HTML used as the next control button. Leave empty for the default arrow icon. | ||
| string |
| Custom HTML used as the previous control button. | ||
| number |
| Index of the slide that is shown first when the gallery opens. | ||
| string |
| Width of the iframe used for | ||
| string |
| Height of the iframe used for | ||
| string |
| Maximum width of the iframe. | ||
| string |
| Maximum height of the iframe. | ||
| boolean |
| If | ||
| boolean |
| If | ||
| string |
| CSS selector of the element that the counter is appended to. | ||
| number (px) |
| Minimum distance (in pixels) the user has to swipe before the next or previous slide is shown. | ||
| boolean |
| Enable touch-swipe support on touch devices. | ||
| boolean |
| Enable mouse-drag support on desktop browsers. | ||
| boolean |
| If | ||
| array |
| Array of slide objects used in dynamic mode. Each object accepts the keys listed in the Dynamic variables table below ( | ||
| array |
| Names of extra | ||
| function |
| A user-supplied function that returns | ||
| object | see below | Options that override the matching core settings on touch devices. The defaults are | ||
| array |
| Array of plugin classes to load. Order does not matter. Example: | ||
| object | see below | Translation strings used by the core toolbar buttons and error messages. The default object is |
Transition styles
lightGallery comes with a long list of CSS transitions for moving from one slide to the next. Use the mode option to pick the one you like:
| Style | Description |
|---|---|
| Default. Slides move horizontally, the new slide enters from the right (or from the left when going backwards). |
| The current slide fades out and the next slide fades in. No horizontal motion. |
| The new slide zooms in from a smaller scale. The |
| The current slide zooms out and disappears, then the next slide appears at full size. The |
| Combines a zoom-out on the leaving slide with a zoom-in on the entering slide. |
| Subtle zoom transition – similar to |
| The new slide scales up from |
| Slide transition with a circular reveal. The vertical variant reveals the new slide from top to bottom instead of left to right. |
| Slides move vertically (top to bottom). The |
| Plain skew transition – the slide tilts as it moves. The |
| Same as |
| Combined slide + skew transition. The slide moves horizontally and tilts at the same time. |
| Slide + skew transition where the leaving and entering slides skew in opposite directions, producing a cross-over effect. |
| Vertical version of |
| Vertical version of |
| Skew + scale + slide combination that gives a "swing" effect (like a swinging lollipop). The |
| Slide transition combined with a rotation. The |
| Slides appear to come out of a tube – horizontal slide combined with a small perspective tilt. |
Data attributes
Each slide can be configured through data-* attributes on its container element. lightGallery reads these attributes when the gallery is built.
| Name | Description |
|---|---|
| URL of the large image or video. Required, unless |
| Caption HTML. May be either the literal HTML of the caption (e.g. |
| URL of an external file whose contents are loaded as the caption. Useful for very long captions. |
|
|
| URL of the poster image used as the placeholder for a video slide. |
| Comma-separated list of image URLs and breakpoints. Example: |
| Standard |
| Standard |
| Set to |
| Custom download URL. Pass |
| Natural width of the image in pixels. Used by the zoom plugin to display the actual size on a double-click. |
| URL used by the share plugin’s Facebook button. Defaults to the current page URL. |
| URL used by the share plugin’s Twitter button. Defaults to the current page URL. |
| Pre-filled tweet text used by the share plugin’s Twitter button. |
| URL used by the share plugin’s Pinterest button. Defaults to the current page URL. |
| Pre-filled description used by the share plugin’s Pinterest button. |
Methods
The lightGallery() function returns the instance of the gallery. All methods are called directly on that instance.
const galleryEl = document.getElementById('my_gallery');
const lg = lightGallery(galleryEl, { selector: 'a' });
// Open the gallery on the third slide (index = 2)
lg.openGallery(2);| Name | Parameters | Description |
|---|---|---|
|
| Open the gallery. |
|
| Go to a specific slide. |
|
| Move to the next slide. |
|
| Move to the previous slide. |
|
| Close the gallery. Pass |
|
| Refresh the gallery. Call this method after the underlying DOM has changed (slides added, removed or reordered). In dynamic mode you can also pass an array of new slide objects. |
|
| Replace the current slide list with a new one and jump to the slide at |
| – | Close the gallery (if open) and tear down all event listeners. After this call the instance can no longer be used. |
Dynamic variables
The objects passed to dynamicEl accept the following keys (all are optional unless noted):
| Name | Description |
|---|---|
| URL of the large image or video. Required. |
| URL of the thumbnail image used by the thumbnail plugin and the zoom-from-thumbnail animation. |
| Caption HTML, the |
| URL of an external caption file (loaded with |
|
|
|
|
| JSON object describing a video source. Used to render video slides without a separate |
| URL of the poster image for video slides. |
| Comma-separated list of image URLs and breakpoints (same syntax as |
| Standard |
| Standard |
| Set to |
| Custom download URL. Pass |
| Natural width of the image (used by the zoom plugin). |
| Custom slide name used by the hash plugin (when |
Events
lightGallery dispatches a number of custom events on the gallery container element. Listen to them with the standard addEventListener() API:
const galleryEl = document.getElementById('my_gallery');
const lg = lightGallery(galleryEl, { selector: 'a' });
// Run before the gallery opens
galleryEl.addEventListener('lgBeforeOpen', (event) => {
console.log('lgBeforeOpen');
});
// Run before each slide change.
// event.detail = { prevIndex, index, fromTouch, fromThumb }
galleryEl.addEventListener('lgBeforeSlide', (event) => {
const { prevIndex, index, fromTouch, fromThumb } = event.detail;
console.log('lgBeforeSlide', prevIndex, index, fromTouch, fromThumb);
});| Event Type | event.detail | Description |
|---|---|---|
|
| Fired when the gallery instance is created (immediately after |
| – | Fired right before the opening animation starts. |
| – | Fired right after the opening animation has finished. |
|
| Fired when the slide content has been inserted into its slide container. |
|
| Fired when the caption (sub-html) has been appended to the slide. |
|
| Fired once the image (or video poster) inside the slide has finished loading. |
|
| Fired right before each slide transition. |
|
| Fired right after each slide transition. |
|
| Fired right before a previous slide transition. |
|
| Fired right before a next slide transition. |
| – | Fired when the user clicks on the poster image of a video slide. |
| – | Fired when the user starts dragging a slide. |
| – | Fired periodically while a drag operation is in progress. |
| – | Fired when the user lets go after a drag. |
|
| Fired when a slide that contains a video is being prepared. |
| – | Fired when the gallery container is resized (window resize, mobile orientation change, …). |
| – | Fired when |
|
| Fired by the rotate plugin after a left rotation. |
|
| Fired by the rotate plugin after a right rotation. |
|
| Fired by the rotate plugin after a horizontal flip. |
|
| Fired by the rotate plugin after a vertical flip. |
|
| Fired by the autoplay plugin every time the autoplay timer moves to the next slide. |
|
| Fired by the autoplay plugin when autoplay starts. |
|
| Fired by the autoplay plugin when autoplay stops. |
| – | Fired right before the closing animation starts. |
| – | Fired once the gallery has been fully closed. |
Plugins
lightGallery plugins add extra features to the lightbox view, such as a thumbnail strip, a full-screen button, autoplay, social-share buttons or rotate controls. Plugins are loaded with the plugins option of the core – just import the plugin script in the HTML head and add the plugin class to the array:
<script src="js/plugins/lg-thumbnail.min.js"></script>
<script src="js/plugins/lg-zoom.min.js"></script>
<script>
lightGallery(document.getElementById('my_gallery'), {
selector: 'a',
plugins: [lgThumbnail, lgZoom]
});
</script>Thumbnails Plugin
You need to include the thumbnail plugin (lg-thumbnail.min.js) to use the options below. The plugin shows a strip of thumbnails at the bottom of the gallery and lets the user jump to any slide by clicking its thumbnail.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the thumbnail strip. |
| boolean |
| Animate the thumbnail strip when the active slide changes. |
| string |
| Where to position the active thumbnail inside the strip. Allowed values: |
| string |
| Vertical alignment of the thumbnail strip. Allowed values: |
| number (px) |
| Width of each thumbnail in pixels. |
| string |
| Height of each thumbnail (CSS length). |
| number (px) |
| Spacing between two thumbnails in pixels. |
| string |
| CSS selector of the element the thumbnail strip is appended to. |
| boolean |
| If |
| boolean |
| Enable mouse-drag support for the thumbnail strip (desktop). |
| boolean |
| Enable touch-swipe support for the thumbnail strip (mobile). |
| number (px) |
| Minimum swipe distance (in pixels) before the thumbnail strip starts to scroll. |
| boolean |
| Automatically load the YouTube poster image as the thumbnail of YouTube video slides. |
| string | number |
| Size of the auto-generated YouTube thumbnail. See the YouTube ThumbSizes table below for the allowed values. |
| object |
| Translation strings used by the thumbnail plugin. |
YouTube ThumbSizes
| Value | Size | Description |
|---|---|---|
| 480x360 pixels | Player background thumbnail. |
| 120x90 pixels | Default thumbnail size. |
| 120x90 pixels | Middle thumbnail. |
| 120x90 pixels | End thumbnail. |
| 480x360 pixels | High quality thumbnail. |
| 320x180 pixels | Medium quality thumbnail. |
| 120x90 pixels | Regular quality thumbnail. |
| 640x480 pixels | Standard definition thumbnail. |
| 1920x1080 pixels | Maximum resolution thumbnail. (default in J1 Template) |
|
|
Autoplay Plugin
You need to include the autoplay plugin (lg-autoplay.min.js) to use the options below. The plugin starts a slideshow timer when the gallery opens (or only when the user clicks the play button).
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the autoplay plugin. Set to |
| boolean |
| If |
| number (ms) |
| Time between two automatic slide changes, in milliseconds. |
| boolean |
| Show a progress bar at the top of the gallery while autoplay is running. |
| boolean |
| If |
| boolean |
| Show the play / pause button in the toolbar. |
| string |
| CSS selector of the element the autoplay button is appended to. |
| object |
| Translation strings used by the autoplay plugin. |
Video Plugin
You need to include the video plugin (lg-video.min.js) to use the options below. The plugin handles YouTube, Vimeo, Dailymotion, VK, and HTML5 video sources transparently.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| If |
| boolean |
| If |
| boolean |
| If |
| object | boolean |
| Pass an object of YouTube player parameters here to customise the embedded YouTube player. See the YouTube Player Parameters documentation for the full list. Example |
| object | boolean |
| Pass an object of HTML5 |
| boolean |
| Use the video.js player to render HTML5 video slides. Requires loading the video.js library separately. |
| string |
| Custom CSS class added to video.js players. Useful for applying a video.js theme. |
| object |
| Options passed to the video.js player when |
Fullscreen Plugin
You need to include the fullscreen plugin (lg-fullscreen.min.js) to use the options below. The plugin adds a fullscreen toggle button to the toolbar; clicking it switches the browser into real-fullscreen mode (using the standard requestFullscreen() API).
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the fullscreen plugin. |
| object |
| Translation strings used by the fullscreen plugin. |
Pager Plugin
You need to include the pager plugin (lg-pager.min.js) to use the options below. The plugin shows a small dot for every slide at the bottom of the gallery; the user can click any dot to jump directly to that slide.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the pager plugin. |
Zoom Plugin
You need to include the zoom plugin (lg-zoom.min.js) to use the options below. The plugin lets the user zoom into images using the mouse wheel, double-click, double-tap or pinch gestures.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the zoom plugin. |
| number |
| How much each zoom step zooms in or out. A value of |
| boolean |
| If |
| boolean |
| Enable the actual size icon (a button that resets the zoom to the natural pixel size of the image). |
| boolean |
| If |
| object |
| CSS class names used for the zoom-in and zoom-out icons. |
| number (ms) |
| Number of milliseconds to wait after a slide change before enabling the zoom. Increase this value if your custom CSS animations on the image conflict with the zoom transitions. |
| object |
| Translation strings used by the zoom plugin. |
Hash Plugin
You need to include the hash plugin (lg-hash.min.js) to use the options below. The plugin updates the URL hash (#lg=1&slide=3) every time the user moves to another slide, so the gallery state becomes bookmarkable. Visiting a URL that already contains a matching hash opens the gallery on that slide.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the hash plugin. |
| string | number |
| Unique id used in the URL hash. Required when several galleries on the same page use the hash plugin (each gallery needs a different id). |
| boolean |
| If |
Share Plugin
You need to include the share plugin (lg-share.min.js) to use the options below. The plugin adds a share dropdown button to the toolbar with one entry per supported social network. You can also add your own targets through the additionalShareOptions array.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the share plugin. |
| boolean |
| Show the Facebook share entry. |
| string |
| Label of the Facebook dropdown entry. |
| boolean |
| Show the Twitter share entry. |
| string |
| Label of the Twitter dropdown entry. |
| boolean |
| Show the Pinterest share entry. |
| string |
| Label of the Pinterest dropdown entry. |
| array |
| Array of custom share targets. Each entry is an object with the keys |
| object |
| Translation strings used by the share plugin. |
Rotate Plugin
You need to include the rotate plugin (lg-rotate.min.js) to use the options below. The plugin adds rotate-left, rotate-right, flip-horizontal and flip-vertical buttons to the toolbar.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the rotate plugin. |
| number (ms) |
| Length of the rotate / flip animation, in milliseconds. |
| boolean |
| Show the rotate-left button. |
| boolean |
| Show the rotate-right button. |
| boolean |
| Show the flip-horizontal button. |
| boolean |
| Show the flip-vertical button. |
| object |
| Translation strings used by the rotate plugin. |
Comment Plugin
You need to include the comment plugin (lg-comment.min.js) to use the options below. The plugin adds a comments sidebar that embeds either Facebook comments or Disqus comments next to each slide.
| Name | Type | Default | Description |
|---|---|---|---|
| boolean |
| Enable the comment plugin. Set to |
| boolean |
| Enable Facebook comments. Each slide may carry an |
| boolean |
| Enable Disqus comments. Each slide may carry the |
| object |
| Disqus configuration. Set |
| string | see source | HTML markup used for the comment sidebar. The default markup contains the empty |
| object |
| Translation strings used by the comment plugin. |