Guide

Plain images

Open the viewer from any img with data attributes.

<ZoomImage> is only a shortcut for a few attributes. Any <img> with data-image-viewer opens the viewer — HTML from a CMS, rendered Markdown, a third-party component.

<img
  src="/photos/dawn-800.jpg"
  alt="Alpine dawn"
  tabindex="0"
  data-image-viewer
  data-image-viewer-src="/photos/dawn.jpg"
  data-image-viewer-width="2400"
  data-image-viewer-height="1600"
  data-image-viewer-caption="Alpine dawn"
>

Attributes

data-image-viewer
boolean required
Marks the image. Only <img> elements are picked up.
data-image-viewer-src
string
The full image. Defaults to the image on the page (currentSrc).
data-image-viewer-width
number
Natural width of the full image. Defaults to the natural width of the page image.
data-image-viewer-height
number
Natural height of the full image. Defaults to the natural height of the page image.
data-image-viewer-caption
string
Caption under the image in the viewer.
data-image-viewer-group
boolean
On a container: the viewer scrolls through the marked images inside it only.
Add tabindex="0" so keyboard users can reach the image and open it with Enter or Space — <ZoomImage> does it for you.

Markdown content

With Nuxt Content, mark the images of a page in one place — a prose image component:

components/content/ProseImg.vue
<script setup lang="ts">
defineProps<{ src: string, alt?: string, width?: number, height?: number }>()
</script>

<template>
  <img
    :src
    :alt
    :width
    :height
    tabindex="0"
    data-image-viewer
  >
</template>

Then wrap the article in data-image-viewer-group so each page is its own gallery.

Turning automatic opening off

The plugin listens to clicks and keys on the whole document. To open the viewer only from code, turn it off:

nuxt.config.ts
export default defineNuxtConfig({
  imageViewer: {
    autoOpen: false,
  },
})