A tiny, dependency-free image lightbox: galleries, zoom & pan, keyboard and swipe navigation.
One JS file and one CSS file, no build step. Works as a plain <script> or as an import (Svelte, React, Vite, …).
npm install github:kagisearch/image-frameOr copy image-frame.js and image-frame.css into your project.
<link rel="stylesheet" href="image-frame.css">
<script src="image-frame.js"></script>
<script>
const frame = new ImageFrame({
container: document.querySelector('.changelog'),
group: '.item',
});
</script><script>
import ImageFrame from 'image-frame';
import 'image-frame/image-frame.css';
const imageFrame = (node) => {
const frame = new ImageFrame({ container: node, group: 'article' });
return () => frame.destroy();
};
</script>
<div {@attach imageFrame}>
{@html entry.html}
</div>Clicks are delegated from container, so images added later (e.g. via {@html}) work without re-initialising.
| Option | Default | Description |
|---|---|---|
container |
document |
Only images inside it open the frame. |
selector |
'img' |
Which images open the frame. Images inside a link (<a>) are always skipped. |
group |
null |
Ancestor selector that forms one gallery. null = all matching images in container. |
zoom |
true |
Show the zoom toggle (hidden on screens ≤ 768px). |
←/→previous / next,Escexits zoom, then closes.- Swipe left / right on touch screens.
- When zoomed, drag to pan.
Set any of these custom properties on :root (or any ancestor of <body>):
:root {
--image-frame-backdrop: rgba(0, 0, 0, 0.85);
--image-frame-button-bg: #2b2b2b;
--image-frame-button-fg: #fff;
--image-frame-accent: #fff; /* button hover / focus background */
--image-frame-accent-fg: #111;
--image-frame-count-bg: #3a3a3a;
--image-frame-count-fg: #ddd;
--image-frame-z-index: 100;
}