Simple and lightweight JavaScript lightbox.
- Simple
- Mobile friendly
- Touch and swipe support
- Keyboard navigation
- Lightweight
-
Download the zip file of the latest release from GitHub. You will find HTML, JS and a CSS file inside.
-
Include the CSS file at the top of your page in the head section:
<link href="path/to/pure-js-lightbox-core.css" rel="stylesheet" />
-
Place the script tag at the bottom of your page right before the closing body tag:
<script src="path/to/pure-js-lightbox-core.js"></script>
-
Add
<img>
tags with attributes to your html:<img class="preview-image" data-lightbox-id="nature" src="images/1.jpg" alt="Goettingen/Diemarden: Hay Bales After Mowing" data-photographer="© light.tales.photography by Micha Z." />
-
Add markup for overlay:
<div class="lightbox-overlay hidden"></div>
-
Add markup for backdrop:
<div class="lightbox-backdrop hidden"></div>
Attribute | Required/Optional | Description |
---|---|---|
class | required | Defaults to preview-image . |
data-lightbox-id | required | Distinguish images between multiple image sets. |
src | required | Relative image path. For example: images/3.jpg . |
alt | optional | Text appears under the image. |
data-photographer | optional | Source of the image. Appears under the image. |
For installation cd into the project root and run npm install
.
To serve on localhost run npm run start
on the command line.
For a production build run npm run build
on the command line.
This will generate a public
directory with index.html
, pure-js-lightbox-core.js
, pure-js-lightbox-core.css
and loading-animation.svg
.
TypeScript is JavaScript with syntax for types.
CSS with superpowers.
Module Bundler for JavaScript.
Demo images for the repository.
Beautiful demo images (on the demo web page).