Categories: CSSScriptWeb Design

Multi-purpose Lightbox Gallery With JavaScript – Ensemble Lightbox

Ensemble Lightbox is a responsive, feature-rich lightbox gallery built using plain JavaScript, with zero dependencies.

Features:

  • Supports any content types: image, text, iframe, video, pdf, etc.
  • Supports modern image formats: webp and avif.
  • Supports dynamic content creation.

How to use it:

1. To get started, include the Ensemble Lightbox’s JavaScript and Stylesheet on the page.

<link rel=”stylesheet” href=”dist/css/ensemble-lightbox.min.css” />
<script src=”dist/js/ensemble-lightbox.min.js”></script>

2. Create a lightbox gallery from elements within the document.

<div

Sponsored
class="example"> <a href="1.jpg"> <img src="1.jpg" alt="Image Caption" /> </a> <a href="iframe.html" data-caption="iframe"> <img src="iframe.jpg" alt="Image Caption" /> </a> <a href="pdf.pdf" data-caption="pdf"> <img src="pdf.jpg" alt="Image Caption" /> </a> // ... </div>
const lightbox_example = document.querySelectorAll('.example');
for (const lightbox_group of lightbox_example) {
  var lightbox_options = { selector: 'a' };
  if (lightbox_group === lightbox_example[1]) {
    lightbox_options.infinite = false;
  }
  const lightbox = new ensemble.Lightbox(lightbox_group, lightbox_options);
  for (const a of lightbox_group.querySelectorAll('a')) {
    a.addEventListener('click', lightbox.open, true);
  }
}

3. Create a lightbox gallery from elements defined in a JS object.

const lightbox_contents = [
  {
    type: 'element',
    node: (function() { var el = document.createElement('div'); el.innerText = 'Test for a custom element.'; return el; }())
  },
  {
    type: 'video',
    loop: true,
    poster: 'video-test-card.png',
    sources: [
      {
        type: 'video/mp4',
        src: 'video-test-card.mp4'
      },
      {
        type: 'video/webm',
        src: 'video-test-card.webm'
      }
    ]
  },
  {
    type: 'video',
    src: 'https://www.youtube.com/embed/mN0zPOpADL4',
    caption: 'Agent 327: Operation Barbershopnnfrom Blender Studio',
    allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
    allowfullscreen: true //TODO FIX
  },
  {
    type: 'video',
    src: 'https://player.vimeo.com/video/325910798',
    caption: 'Spring - Blender Open Moviennfrom Blender Studio',
    allow: 'autoplay; fullscreen; picture-in-picture',
    allowfullscreen: true //TODO FIX
  },
  {
    type: 'audio',
    src: 'https://open.spotify.com/embed/album/54Awn36ryf55PkZyOR4iwQ',
    allowtransparency: true, //TODO FIX
    allow: 'encrypted-media'
  },
  {
    type: 'iframe',
    src: 'https://docs.google.com/forms/d/e/1FAIpQLSeI8_vYyaJgM7SJM4Y9AWfLq-tglWZh6yt7bEXEOJr_L-hV1A/viewform?formkey=dGx0b1ZrTnoyZDgtYXItMWVBdVlQQWc6MQ',
    height: '100%' //TODO FIX
  },
  {
    type: 'audio',
    src: 'audio-test.wav',
    autoplay: true
  }
  // ...
];
const lightbox = new ensemble.Lightbox({ 
      contents: lightbox_contents 
});

4. All default options.

Sponsored
const lightbox = new ensemble.Lightbox({ 
      className: ['modal', 'modal-lightbox'],
      selector: '',
      contents: null,
      navigation: true,
      captioned: true,
      infinite: true,
      autoDiscover: true,
      autoHide: 'navigation', // "navigation" or "captions"
      overlayed: false,
      checkOrigin: true,
      prev: {
        onclick: this.prev,
        innerText: 'u003C',
        ariaLabel: 'Previous'
      },
      next: {
        onclick: this.next,
        innerText: 'u003E',
        ariaLabel: 'Next'
      },
      onStep: function () {},
      onSlide: function () {},
      onCaption: function () {}
});

Changelog:

04/13/2025

  • update

04/09/2025

  • added swipe to slide, bugfix, refact

The post Multi-purpose Lightbox Gallery With JavaScript – Ensemble Lightbox appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

Zoom Update Scam Infected 1,437 Users to Deploy Surveillance Tools in 12 Days

A cleverly crafted fake Zoom website has silently pushed surveillance software onto Windows machines, infecting…

11 minutes ago

1Campaign Platform Helps Attackers Bypass Google Ads Screening to Show Malicious Ads

A newly uncovered cloaking platform called 1Campaign is giving cybercriminals a powerful tool to push malicious advertisements…

11 minutes ago

The Ultra Slim Lisen 5,000Mah Qi2-Certified Wireless Magnetic Power Bank Drops to $16.99

Apple iPhone users, check out this new deal on an ultra-slim MagSafe power bank that…

21 minutes ago

IGN Live Returns June 6 and 7 2026

IGN Live is back for another year, this year taking place June 6-7 in downtown…

21 minutes ago

New and Exclusive Clip From One Piece Season 2 | IGN Fan Fest 2026

One Piece Season 2 arrives on Netflix on March 10 at 12:00am PDT, and IGN…

21 minutes ago

Qualcomm won’t be announcing Windows gaming handhelds at GDC after all

In January, Qualcomm hinted to The Verge that it might finally bring its powerful Arm-based…

56 minutes ago

This website uses cookies.