Skip to content

Lightbox

@astryxdesign/core v0.7.1 · Lightbox

Coastal shoreline with ocean waves

A scenic coastline with waves rolling onto a sandy beach beneath a clear sky.

Usage ​

Lightbox opens media in a native <dialog>. Bind isOpen with v-model:is-open. A single media object is one image or video. An array is a gallery: previous, next, and a counter stay mounted, and the ends disable instead of disappearing.

useLightbox({ media }) owns the open state and the index. Bind bindings onto Lightbox, and call open(index) from a thumbnail.

hasZoom turns an image into a button. Double-click, Enter, Space, +, and - toggle between 1× and 2×. While zoomed, drag or the arrow keys pan; each arrow moves 50px. A drag does not also close the dialog. Video items keep the browser controls and do not zoom. hasAutoPlay starts a video when that item is shown.

Escape and the close button emit update:isOpen with false. A backdrop click on the dialog or the frame does the same.

vue
<script setup lang="ts">
import { Lightbox, useLightbox } from '@astryx-vue/core/Lightbox'
import { Thumbnail } from '@astryx-vue/core/Thumbnail'

const photo = {
  src: '/template-assets/light-scene-horizontal-1.png',
  alt: 'Coastal shoreline with ocean waves',
  caption: 'A scenic coastline with waves rolling onto a sandy beach beneath a clear sky.',
}
const { bindings, open } = useLightbox({ media: photo })
</script>

<template>
  <Thumbnail :src="photo.src" :alt="photo.alt" :label="photo.alt" @click="open()" />
  <Lightbox v-bind="bindings" />
</template>

Anatomy

ElementDescription
Viewer overlayFull-viewport dialog overlay that contains the active media and controls.
MediaActive image or video presented inside the viewer.
Close buttonButton that closes the viewer.
Previous buttonGallery button that moves to the previous media item.
Next buttonGallery button that moves to the next media item.
CaptionCaller-provided caption displayed below the active media.
CounterCurrent position and total shown in gallery mode.

Best practices ​

GuidancePractices
DoWrite an alt that names the picture, and a caption that adds what the picture itself does not say.
DoOpen a gallery at the thumbnail the reader chose, with open(index).
DoTurn on hasZoom only for a still image that has detail worth inspecting.
Don'tPut hasZoom on a video. The controls stay native, and zoom is ignored.
Don'tLeave alt empty. The dialog name and the image name both come from it.

Examples ​

Gallery

Backpack

A backpack displayed on a neutral background.

1 / 4

A thumbnail grid that opens a fullscreen gallery. Clicking any thumbnail opens the lightbox at that index. Previous and next browse the rest without closing.

Video

A flower blooming in time-lapse

Opens a video with the browser controls. Zoom and pan stay off for video.

Zoom

Coastal shoreline with ocean waves

A scenic coastline. Double-click to zoom in and drag to pan.

Double-click the image to zoom in, then drag to pan. Double-click again, or close, to leave zoom.