### Installation via Bower
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Install GLightbox using Bower.
```bash
bower install glightbox
```
--------------------------------
### Installation via Yarn
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Install GLightbox using Yarn.
```bash
yarn add glightbox
```
--------------------------------
### Install dependencies and watch for changes
Source: https://github.com/biati-digital/glightbox/blob/master/CONTRIBUTING.md
Commands to install project dependencies and start the development watch process.
```bash
npm install
npm run watch
```
--------------------------------
### Audio Files
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Example of linking to audio files.
```html
```
--------------------------------
### Development Commands
Source: https://github.com/biati-digital/glightbox/blob/master/README.md
Commands to install dependencies and start the development watch process.
```bash
$ npm install
$ npm run watch
```
--------------------------------
### Basic Examples
Source: https://github.com/biati-digital/glightbox/blob/master/README.md
Examples demonstrating how to use GLightbox for simple images, videos, galleries, and content with descriptions.
```html
The content of this div will be used as the slide description
You can add links and any HTML you want
```
--------------------------------
### getAllPlayers() Example
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md
Shows how to get all video player instances in the gallery and iterate through them.
```javascript
const allPlayers = lightbox.getAllPlayers();
for (const playerId in allPlayers) {
const player = allPlayers[playerId];
console.log(player);
}
```
--------------------------------
### Installation
Source: https://github.com/biati-digital/glightbox/blob/master/README.md
Instructions for installing GLightbox using npm, yarn, or bower.
```bash
$ npm install glightbox
# OR
$ yarn add glightbox
# OR
$ bower install glightbox
```
--------------------------------
### Basic Setup
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/INDEX.md
Import GLightbox and initialize it with a selector.
```javascript
import GLightbox from 'glightbox';
const lightbox = GLightbox({
selector: '.glightbox'
});
```
--------------------------------
### Constructor Options Example
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/configuration.md
Example of initializing GLightbox with various constructor options.
```javascript
const lightbox = GLightbox({
selector: '.glightbox',
openEffect: 'zoom',
closeEffect: 'zoom',
slideEffect: 'slide',
// ... more options
});
```
--------------------------------
### Self-Hosted Video
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Example of linking to self-hosted video files.
```html
This will append some html inside the slide
' // read more in the API section }, { 'content': document.getElementById('inline-example') // this will append a node inside the slide }, ], autoplayVideos: true, }); myGallery.open(); // If later you need to modify the elements you can use setElements myGallery.setElements([...]); ``` -------------------------------- ### open Event Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Example of an event listener for the 'open' event. ```javascript lightbox.on('open', () => { console.log('Lightbox is now open'); }); ``` -------------------------------- ### version() Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Retrieves and logs the current version of GLightbox. ```javascript console.log(lightbox.version()); // "3.3.1" ``` -------------------------------- ### YouTube Videos Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Examples of linking to YouTube videos using different URL formats. ```html
```
--------------------------------
### GLightboxInit Class: goToSlide() Method Example
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md
Demonstrates navigating to a specific slide by index.
```javascript
lightbox.goToSlide(2);
```
--------------------------------
### Custom Animations
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Example of configuring custom open and close animations using CSS effects.
```javascript
const lightbox = GLightbox({
openEffect: 'bounce',
closeEffect: 'bounce',
cssEffects: {
bounce: {
in: 'bounceIn',
out: 'bounceOut'
}
}
});
```
```css
@keyframes bounceIn {
from {
opacity: 0;
transform: scale(0.3);
}
to {
opacity: 1;
transform: scale(1);
}
}
.gbounceIn {
animation: bounceIn 0.6s ease-out;
}
@keyframes bounceOut {
from {
opacity: 1;
transform: scale(1);
}
to {
opacity: 0;
transform: scale(0.3);
}
}
.gbounceOut {
animation: bounceOut 0.6s ease-in;
}
```
--------------------------------
### Using Configuration Objects
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/configuration.md
Example of configuring individual slides using JavaScript objects.
```javascript
const lightbox = GLightbox({
elements: [
{
href: 'image.jpg',
type: 'image',
title: 'My Title',
description: 'My description',
descPosition: 'left',
width: '800px',
height: '600px',
zoomable: false,
draggable: false
}
]
});
```
--------------------------------
### From DOM Element
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Initializes GLightbox with content from a DOM element.
```javascript
const content = document.getElementById('my-element');
const lightbox = GLightbox({
elements: [
{
content: content,
width: 'auto'
}
]
});
lightbox.open();
```
--------------------------------
### GLightboxInit Class: destroy() Method Example
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md
Demonstrates how to completely destroy the lightbox instance.
```javascript
lightbox.destroy();
```
--------------------------------
### AJAX example with GLightbox
Source: https://github.com/biati-digital/glightbox/blob/master/README.md
Illustrates how to use GLightbox with AJAX calls, creating an instance, inserting dynamic content, and opening the lightbox.
```javascript
// So imagine that you are making an ajax request that returns some html
// You can create an empty instance and append the content once is returned
const ajaxExample = GLightbox({ selector: null }); // or you can set the selector empty selector: ''
doAjaxCall({...}).then(response => {
ajaxExample.insertSlide({
width: '500px',
content: response.html
});
ajaxExample.open();
})
// Or you could use the set elements method to empty all the slides if any
doAjaxCall({...}).then(response => {
ajaxExample.setElements([
{
content: response.html
}
]);
ajaxExample.open();
})
```
--------------------------------
### From HTML String
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Initializes GLightbox with inline HTML content provided as a string.
```javascript
const lightbox = GLightbox({
elements: [
{
content: 'This is inline HTML
', width: '600px' } ] }); lightbox.open(); ``` -------------------------------- ### close Event Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Example of an event listener for the 'close' event. ```javascript lightbox.on('close', () => { console.log('Lightbox is now closed'); }); ``` -------------------------------- ### GLightboxInit Class: reload() Method Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Shows how to reload the lightbox, useful after dynamic content changes. ```javascript // After adding new elements to the DOM lightbox.reload(); ``` -------------------------------- ### Vue Integration Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/recipes-and-patterns.md Shows how to integrate GLightbox within a Vue.js component, managing the lightbox instance in `mounted` and `beforeUnmount` hooks. ```vue
a link.">
```
--------------------------------
### Videos Gallery
Source: https://github.com/biati-digital/glightbox/blob/master/index.html
Example of creating a video gallery with support for Vimeo, YouTube, and self-hosted videos.
```html
```
--------------------------------
### slidePlayerPlay() Example
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md
Example of playing a video in a specific slide by its index.
```javascript
lightbox.slidePlayerPlay(1); // Play video in slide at index 1
```
--------------------------------
### GLightbox Factory Function Example
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md
Demonstrates basic usage with a selector and programmatic elements.
```javascript
import GLightbox from 'glightbox';
// Basic usage with selector
const lightbox = GLightbox({
selector: '.glightbox',
openEffect: 'zoom',
closeEffect: 'zoom'
});
// Usage with programmatic elements
const myGallery = GLightbox({
elements: [
{
href: 'https://example.com/image1.jpg',
type: 'image',
title: 'Image 1'
},
{
href: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
type: 'video',
width: 900
}
]
});
myGallery.open();
```
--------------------------------
### Video Configuration
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Configures video playback options for GLightbox.
```javascript
const lightbox = GLightbox({
videosWidth: '960px',
autoplayVideos: true,
autofocusVideos: false,
plyr: {
css: 'https://cdn.plyr.io/3.6.12/plyr.css',
js: 'https://cdn.plyr.io/3.6.12/plyr.js',
config: {
ratio: '16:9',
youtube: {
noCookie: true,
rel: 0,
iv_load_policy: 3
},
vimeo: {
byline: false,
portrait: false,
title: false
}
}
}
});
```
--------------------------------
### Iframes and Inline Elements
Source: https://github.com/biati-digital/glightbox/blob/master/index.html
Example of embedding iframes and inline HTML content.
```html
```
--------------------------------
### Custom HTML Structure
Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md
Demonstrates how to provide a custom HTML structure for the lightbox.
```javascript
const customLightboxHTML = `
Custom HTML content
', width: '500px' }, 1); ``` -------------------------------- ### Replace All Slides Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Illustrates how to replace all existing slides with a new set of slides. ```javascript lightbox.setElements([ { href: 'image1.jpg', type: 'image' }, { href: 'image2.jpg', type: 'image' }, { href: 'https://vimeo.com/123456', type: 'video' } ]); ``` -------------------------------- ### Default Animations Source: https://github.com/biati-digital/glightbox/blob/master/README.md Example of how to configure default animations for GLightbox, including zoom and fade effects. ```javascript const glightbox = GLightbox({ openEffect: 'zoom', closeEffect: 'fade', cssEfects: { // This are some of the animations included, no need to overwrite fade: { in: 'fadeIn', out: 'fadeOut' }, zoom: { in: 'zoomIn', out: 'zoomOut' } } }); ``` -------------------------------- ### setElements() Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Illustrates replacing the gallery slides with a new set of elements, including images, videos, and inline content. ```javascript lightbox.setElements([ { href: 'https://picsum.photos/1200/800', type: 'image', title: 'New Gallery 1' }, { href: 'https://www.youtube.com/watch?v=Ga6RYejo6Hk', type: 'video', width: '900px' }, { content: 'Inline content
', width: '500px' } ]); ``` -------------------------------- ### Simple Image Gallery Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/INDEX.md HTML structure for a simple image gallery using GLightbox. ```html
some html to append in the slide
', 'width': '900px', } ]); ``` -------------------------------- ### Remove Slides Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Shows how to remove a slide from the lightbox by its index. ```javascript lightbox.removeSlide(2); // Remove slide at index 2 ``` -------------------------------- ### Slide Load Events Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Listens for events before and after a slide is loaded. ```javascript lightbox.on('slide_before_load', (data) => { console.log('Loading slide', data.slideIndex); }); lightbox.on('slide_after_load', (data) => { console.log('Slide loaded and rendered'); // Modify the slide after it's loaded const slide = data.slideNode; slide.style.border = '2px solid gold'; }); ``` -------------------------------- ### GLightbox Event Listeners Source: https://github.com/biati-digital/glightbox/blob/master/README.md Examples of how to listen for 'slide_inserted' and 'slide_removed' events in GLightbox. ```javascript lightbox.on('slide_inserted', (data) => { // data is an object that contain the following const { slideIndex, slideNode, slideConfig, player, trigger } = data; // slideIndex - the slide index // slideNode - the node you can modify // slideConfig - will contain the configuration of the slide like title, description, etc. // player - the slide player if it exists otherwise will return false // trigger - null }); // Trigger a function when a slide is removed lightbox.on('slide_removed', (index) => { // index is the position of the element in the gallery }); ``` -------------------------------- ### on() Event Listener Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Registers event listeners for 'slide_changed' and 'open' events. ```javascript lightbox.on('slide_changed', (data) => { console.log('Slide changed to:', data.current.slideIndex); }); lightbox.on('open', () => { console.log('Lightbox opened'); }); ``` -------------------------------- ### Completely Programmatic Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/recipes-and-patterns.md Initializes GLightbox without needing any DOM elements, providing elements directly via the API. ```javascript // No DOM elements needed const gallery = GLightbox({ elements: [ { href: 'image1.jpg', type: 'image' }, { href: 'image2.jpg', type: 'image' } ] }); ``` -------------------------------- ### Slide Modification Events Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Listens for events when slides are inserted or removed. ```javascript lightbox.on('slide_inserted', (data) => { console.log('Slide inserted at index', data.slideIndex); }); lightbox.on('slide_removed', (index) => { console.log('Slide at index', index, 'was removed'); }); ``` -------------------------------- ### Slide Change Events Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Listens for events related to slide changes. ```javascript lightbox.on('slide_before_change', ({ prev, current }) => { console.log('Changing from slide', prev.slideIndex, 'to', current.slideIndex); }); lightbox.on('slide_changed', ({ prev, current }) => { console.log('Now viewing slide', current.slideIndex); if (current.player) { console.log('This slide contains a video'); } }); ``` -------------------------------- ### Open & Close Events Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Listens for lightbox open and close events. ```javascript const lightbox = GLightbox(); lightbox.on('open', () => { console.log('Lightbox opened'); }); lightbox.on('close', () => { console.log('Lightbox closed'); }); ``` -------------------------------- ### Programmatic Gallery Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/configuration.md Creating a gallery programmatically with a list of elements and options, and opening it. ```javascript const gallery = GLightbox({ elements: [ { href: 'https://picsum.photos/1200/800?random=1', type: 'image', title: 'Image 1', description: 'First image in the gallery' }, { href: 'https://picsum.photos/1200/800?random=2', type: 'image', title: 'Image 2', description: 'Second image in the gallery' }, { href: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', type: 'video', title: 'YouTube Video', width: 900 } ], loop: true }); gallery.open(); ``` -------------------------------- ### Global Description Position Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Sets the global position for slide descriptions. ```javascript const lightbox = GLightbox({ descPosition: 'left' // 'bottom', 'top', 'left', 'right' }); ``` -------------------------------- ### Add Slides from API Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/recipes-and-patterns.md Demonstrates how to dynamically add multiple slides to the lightbox from an API response. ```javascript const gallery = GLightbox({ elements: [] }); async function loadMoreSlides() { const response = await fetch('/api/images'); const images = await response.json(); images.forEach(image => { gallery.insertSlide({ href: image.url, type: 'image', title: image.title, description: image.caption }); }); gallery.open(); } document.getElementById('load-btn').addEventListener('click', loadMoreSlides); ``` -------------------------------- ### Responsive Styling Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/recipes-and-patterns.md Optimize GLightbox styling for mobile devices using media queries. ```css /* Mobile optimizations */ @media (max-width: 768px) { .glightbox-custom .gslider { padding: 10px; } .glightbox-custom .gbtn { width: 40px; height: 40px; } .glightbox-custom .gslide-description { font-size: 14px; } } ``` -------------------------------- ### GLightboxInit Class: removeSlide() Method Example Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/api-reference.md Illustrates removing a slide at a specified index. ```javascript lightbox.removeSlide(2); ``` -------------------------------- ### Open at Specific Index Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/recipes-and-patterns.md Demonstrates how to open the lightbox and optionally specify which slide to display first, either programmatically or from an element. ```javascript const lightbox = GLightbox(); // Open gallery lightbox.open(); // Open at a specific slide lightbox.openAt(3); // Open triggered by an element const element = document.querySelector('.gallery-item'); lightbox.open(element); // Open at index from data attribute const index = parseInt(element.dataset.index); lightbox.open(null, index); ``` -------------------------------- ### Selector-Based Gallery Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/configuration.md Initializing GLightbox with a specific selector and custom effects. ```javascript const lightbox = GLightbox({ selector: '.image-gallery', openEffect: 'fade', closeEffect: 'fade', slideEffect: 'fade' }); ``` -------------------------------- ### Track Navigation Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/recipes-and-patterns.md Demonstrates how to use event listeners to track slide navigation, including before and after slide changes. ```javascript const lightbox = GLightbox(); lightbox.on('slide_before_change', ({ prev, current }) => { console.log(`Moving from slide ${prev.slideIndex} to ${current.slideIndex}`); }); lightbox.on('slide_changed', ({ current }) => { console.log(`Now viewing: ${current.slideConfig.title}`); }); ``` -------------------------------- ### Programmatic Galleries Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/usage-guide.md Define slides entirely in JavaScript without HTML markup. ```javascript const gallery = GLightbox({ elements: [ { href: 'image1.jpg', type: 'image', title: 'Image 1', description: 'First slide' }, { href: 'image2.jpg', type: 'image', title: 'Image 2' }, { href: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', type: 'video', title: 'YouTube Video', width: 900 }, { href: 'video.mp4', type: 'video', source: 'local', width: '90vw' }, { content: 'Custom HTML content
', width: '500px' }, { content: document.getElementById('my-element'), width: 'auto' } ], loop: true, autoplayVideos: true }); gallery.open(); ``` -------------------------------- ### DOM Element Content Source: https://github.com/biati-digital/glightbox/blob/master/_autodocs/slides-and-content-types.md Example of inserting a direct DOM element into a slide. ```javascript const element = document.getElementById('my-element'); lightbox.insertSlide({ content: element, width: 'auto', height: 'auto' }); ```