npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@divclass/lightbox

v1.0.2

Published

Divclass Lightbox — modern, lightweight lightbox for images and inline content. Only 32 KB (≈11 KB gzipped). Touch-friendly, cross-browser, swipe & drag gestures, virtual slides, inline HTML, zero dependency.

Readme

Divclass Lightbox

npm version

Lightweight 32 KB (≈11 KB gzipped), dependency-free lightbox for images and inline content.
Supports smart zoom animations, virtual slides, swipe & drag gestures, and works on all modern browsers and touch devices.

Live Demo


🌟 Key Features

  • Lightweight — 32 KB (≈11 KB gzipped)
    Full-featured lightbox without heavy dependencies.
  • Virtual Slides
    Only 3 DOM nodes exist at a time for optimal performance.
  • Fully Responsive
    Works perfectly across desktop, tablet, and mobile devices.
  • Cross-browser & Touch-friendly
    Supports modern browsers and touch gestures.
  • Easy Integration
    Initialize via data attributes or selectors.
  • Smart Zoom From Origin
    Smooth animation from thumbnail → full image without predefined image sizes.
  • Swipe & Drag Gestures
    Intuitive navigation on touch devices
  • Animated Thumbnails & Data Galleries
    Create galleries instantly using data-gallery.
  • Inline Content & Nested Modals
    Display any HTML content and even open nested modals.
  • Smart Image Preloading
    Smooth navigation with optimized image loading.
  • Keyboard Navigation
  • Global Controls
    • DivclassLightbox.closeAll()
    • DivclassLightbox.destroyAll()
  • Customizable Animations

🌍 Demo

https://lightbox.divclass.org


📦 Installation

Install via npm

npm install @divclass/lightbox
import DivclassLightbox from "@divclass/lightbox";
import "@divclass/lightbox/style.css"


new DivclassLightbox("[data-dc-lightbox]")

CDN

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@divclass/lightbox/dist/divclass-lightbox.css">
<script src="https://cdn.jsdelivr.net/npm/@divclass/lightbox/dist/divclass-lightbox.umd.js"></script>

<script>
  new DivclassLightbox('[data-dc-lightbox]');
</script>

ES Modules (browser)

<link rel="stylesheet" href="/path/divclass-lightbox.css">

<script type="module">
  import DivclassLightbox from "/path/divclass-lightbox.esm.js";

  new DivclassLightbox("[data-dc-lightbox]");
</script>

Manual Download

Download the latest release and include the files manually:

<link rel="stylesheet" href="dist/divclass-lightbox.css">

<script src="dist/divclass-lightbox.umd.js"></script>

<script>
  new DivclassLightbox('[data-dc-lightbox]');
</script>

🚀 Quick Start

Add the data-dc-lightbox attribute to links that should open in the lightbox.

<a href="image-large.jpg" data-dc-lightbox>
  <img src="image-thumb.jpg" alt="">
</a>

Initialize the lightbox with a selector:

import DivclassLightbox from "@divclass/lightbox";
import "@divclass/lightbox/style.css"

new DivclassLightbox("[data-dc-lightbox]")

Gallery

Group items into a gallery using the data-gallery attribute.

<a href="img1.jpg" data-dc-lightbox data-gallery="gallery1">
  <img src="thumb1.jpg" alt="">
</a>

<a href="img2.jpg" data-dc-lightbox data-gallery="gallery1">
  <img src="thumb2.jpg" alt="">
</a>

<a href="img3.jpg" data-dc-lightbox data-gallery="gallery1">
  <img src="thumb3.jpg" alt="">
</a>

Caption

Use data-caption to display text or HTML.

<a
  href="image.jpg"
  data-dc-lightbox
  data-caption="Lorem ipsum <p>Custom HTML caption</p>"
>
  <img src="thumb.jpg" alt="">
</a>

Inline Content

You can open any HTML element inside the lightbox.

<a href="#modal-content" data-dc-lightbox>
  Open modal
</a>

<div id="modal-content" style="display:none">
  <h2>Hello</h2>
  <p>This content is displayed inside the lightbox.</p>
</div>

You can also use data-src:

<button data-dc-lightbox data-src="#modal-content">
  Open modal
</button>

Open via JavaScript

You can also open the lightbox programmatically.

DivclassLightbox.show({
  src: "https://picsum.photos/id/10/800/1000/",
  type: "image",
  caption: "Test image",
});

Open inline content:

DivclassLightbox.show({
  src: "#modal-1"
});

Example with additional options:

DivclassLightbox.show({
  src: "https://picsum.photos/id/10/800/1000/",
  type: "image",
  caption: "Auto closing example",
  closeExisting: true,
  autoClose: 2000
});

⚙ Options

| Option | Type | Default | Description | | ---------------------- | ---------------------------------------------------- | -------------- | ------------------------------------------------------ | | icon | string | SVG | Close button icon | | thumbnailsIcon | string | SVG | Thumbnails toggle icon | | arrowIcon | string | SVG | Arrow navigation icon | | showThumbnailsOnOpen | boolean | true | Show thumbnails when gallery opens | | backdropClick | "close" | false | "close" | Close modal when clicking backdrop (inline only) | | closeExisting | boolean | false | Closes any currently open lightbox before opening a new one. | | parentContainer | string | "body" | CSS selector of the container element where the modal will be appended. | | hideScrollbar | boolean | true | Hide body scrollbar when lightbox is open | | effect | "fadeIn" | "fadeInDown" | "fadeInUp" | "zoomIn" | "fadeInUp" | Opening animation | | zoomImageFromOrigin | boolean | true | Animate image from thumbnail position | | animationDuration | number | 400 | Opening/closing animation duration (ms) | | autoClose | false | number | false | Automatically close lightbox after specified time (ms) | | type | "inline" | "image" | "inline" | Default content type | | caption | string | false | false | Caption text or HTML | | slideChangeDuration | number | 280 | Slide transition duration (ms) | | slideOffset | number | 0.1 | Distance offset between slides during drag/swipe navigation. Accepts values from 0 to 1 |


HTML Data Attributes


🎯 Events

Divclass Lightbox provides lifecycle hooks that allow you to interact with the modal during different stages.

const lightbox = new DivclassLightbox('[data-dc-lightbox]');

lightbox.on("layoutReady", ({ modalRef }) => {
  const heading = modalRef.querySelector("h2");

  if (heading) {
    heading.innerHTML = "New Text";
  }
});

Available Events

| Event | Description | | ------------------- | ---------------------------------------------- | | beforeLayoutOpen | Fired before the modal layout is prepared | | layoutReady | Fired when the layout is inserted into the DOM | | layoutOpened | Fired when the modal becomes visible | | beforeLayoutClose | Fired before the modal starts closing | | layoutClosed | Fired after the modal is fully closed |


🌐 Global Methods

DivclassLightbox.show(options)

Open a lightbox programmatically.

DivclassLightbox.closeAll()

Close all currently opened lightboxes.

DivclassLightbox.destroyAll()

Destroy all initialized lightbox instances and remove event listeners.


Why Divclass Lightbox?

Divclass Lightbox focuses on performance and simplicity.

Unlike many heavy lightbox libraries, it keeps the DOM minimal using virtual slides, supports touch gestures, and works with zero dependencies.


🌐 Browser Support

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera

Touch devices fully supported (mobile & tablet).


📄 License

MIT © Taras Bilinskyi