dialog-lightboxv0.3.1

JavaScript

One function starts a lightbox and returns its controls.

Usage

script.js
import { lightbox } from "dialog-lightbox";

const box = lightbox({ gallery, dialog, loop: false, history: true });
box.on("change", (slide) => {
  caption.textContent = slide.link.querySelector("img")?.alt ?? "";
});

Options

OptionDefault
galleryElement whose links are the slides
dialogYour <dialog>
loopfalseAfter the last slide comes the first
historytrueThe back button closes the box, and #dlb=<id> opens a slide

What it returns

lightbox() returns
open(index = 0), close()Open on a slide, or close
next(), prev(), goTo(index)Move while open
current, countThe current slide (null while closed) and the number of slides
videoThe one <video> element
on(event, handler)"open", "change" or "close"; returns a function that removes the handler. change also fires right after open
destroy()Closes without animation and removes every listener. The last lightbox of a dialog also removes the attributes and text it wrote there

A slide is { index, id, type, link }, where link is the thumbnail’s <a>.