Skip to content

About

Tiny dependency-free image lightbox.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

image-frame

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, …).

Install

npm install github:kagisearch/image-frame

Or copy image-frame.js and image-frame.css into your project.

Usage

Plain script

<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>

Import (e.g. Svelte 5)

<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.

Options

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).

Keyboard & touch

  • ← / → previous / next, Esc exits zoom, then closes.
  • Swipe left / right on touch screens.
  • When zoomed, drag to pan.

Theming

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;
}

About

Tiny dependency-free image lightbox.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages