Customization

Options

Global defaults in nuxt.config and overrides per open() call.

Set the options under the imageViewer key. All of them are optional.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-image-viewer'],
  imageViewer: {
    bgOpacity: 0.9,
    maxZoom: 6,
    ui: { fullscreen: false },
    hide: ['#intercom-container'],
  },
})

Options marked per call can also be passed to open() for one viewer — the rest of the options still come from nuxt.config:

useImageViewer().open(items, 0, { loop: false, ui: { counter: false } })

Behaviour

zIndex

number · default 1000 · per call

z-index of the viewer layer. Raise it above your own fixed bars and chat widgets.

bgOpacity

number · default 0.8 · per call

Opacity of the backdrop, 0–1. 1 hides the page completely. The colour is the --image-viewer-bg variable.

loop

boolean · default true · per call

Endless strip: the first image follows the last one. Needs at least 3 images — with two, the neighbour on both sides would be the same slide.

spacing

number · default 0.1 · per call

Gap between slides as a share of the viewport width.

maxZoom

number · default 4 · per call

Upper zoom limit relative to the image fitted into the screen. Images zoom up to their natural size, but at least 2×, and never above this value.

closeOnVerticalDrag

boolean · default true · per call

Close by dragging the image up or down. When off, a vertical drag scrolls the strip like a horizontal one.

closeOnBackdropClick

boolean · default true · per call

Close by a click or a tap outside the image.

idleDelay

number · default 4000 · per call

Fade the controls — buttons, arrows, counter — out after the mouse rests for this long, in milliseconds, so the image is left alone. Any mouse move or key brings them back; over a button they stay. 0 keeps the controls shown. Only on devices with a mouse: touch screens keep the controls.

idleHidesCaption

boolean · default true · per call

Fade the caption out together with the controls. false leaves the image with its caption.

// A clean image after 2 s, but keep the caption
const viewer = useImageViewer()

viewer.open(items, 0, { idleDelay: 2000, idleHidesCaption: false })

Interface

ui

object · per call, partial

Which controls to show. All true by default.

Key
counter2 / 5 in the top left corner. Hidden for a single image.
zoomZoom in / out button.
fullscreenFullscreen button — only where the Fullscreen API exists (not on iPhone).
closeClose button.
arrowsPrevious / next buttons. Hidden on touch screens anyway.
captionCaption under the image.

labels

object · per call, partial

Accessible names of the dialog and its buttons. English by default.

labels: {
  dialog: 'Image viewer',
  close: 'Close',
  zoomIn: 'Zoom in',
  zoomOut: 'Zoom out',
  fullscreen: 'Fullscreen',
  exitFullscreen: 'Exit fullscreen',
  prev: 'Previous',
  next: 'Next',
}

Page integration

openClass

string · default 'image-viewer-open'

Class added to <html> while the viewer is open — handy to hide or adjust things of your own:

.image-viewer-open .cookie-banner {
  display: none;
}

hide

string[] · default []

CSS selectors hidden while the viewer is open. Chat widgets and other things that sit above every layer are the usual suspects.

hide: ['jdiv', '#intercom-container', '.crisp-client']

autoOpen

boolean · default true

Open the viewer on click, Enter and Space on any img[data-image-viewer]. Turn it off to open it only from code.

Build

These are read when the app builds and can't be changed per call.

componentName

string | false · default 'ZoomImage'

Name of the image component. false — don't register it and mark images with the data attributes yourself.

nuxtImage

boolean | 'auto' · default 'auto'

Render <NuxtImg> inside the image component. 'auto' — when @nuxt/image is installed.

css

boolean · default true

Include the default styles. Turn off to style from scratch.

Runtime config

The runtime options also live in useRuntimeConfig().public.imageViewer, so they can be overridden with environment variables:

.env
NUXT_PUBLIC_IMAGE_VIEWER_Z_INDEX=2000
NUXT_PUBLIC_IMAGE_VIEWER_BG_OPACITY=1