Getting started

Getting started

Install the package, import the stylesheet once, then bind the viewer to the element that holds your images.

Install

Lightbox brings Carousel with it for paging.

npm install @reuse-sh/lightbox

Bind a gallery

Every image inside the element opens in the viewer, in page order. With React, the hook opens the same viewer from your own buttons.

import { bindLightboxGallery } from "@reuse-sh/lightbox";
import "@reuse-sh/lightbox/styles.css";

const gallery = document.querySelector("[data-gallery]");
const lightbox = bindLightboxGallery(gallery, {
  thumbnails: true,
  imageClick: "zoom",
});

// Later, when the gallery leaves the page
lightbox.destroy();

Clean up

destroy() removes the listeners and restores every style it changed, so the viewer can come and go with a route. The React hook does this when the component unmounts.