Customization

Recipes

Common setups, copy-paste ready.

Hide a chat widget while the viewer is open

nuxt.config.ts
export default defineNuxtConfig({
  imageViewer: {
    hide: ['jdiv', '#intercom-container', '#crisp-chatbox'],
  },
})
Alpine dawnOcean sunsetDunes at noon

Open an image — the chat bubble in the bottom right corner steps aside until you close it.

Each <ZoomImage> in its own group:

<template>
  <figure data-image-viewer-group>
    <ZoomImage v-bind="photo" />
  </figure>
</template>

Or from code: useImageViewer().open({ src: '/photos/poster.jpg' }).

A starry night
A starry night
Bauhaus tiles — zoom in
Bauhaus tiles — zoom in

Each image opens alone — no counter, no arrows, nothing to swipe to.

<script setup lang="ts">
const { data: photos } = await useFetch('/api/photos')
const viewer = useImageViewer()
</script>

<template>
  <button type="button" @click="viewer.open(photos ?? [])">
    View all {{ photos?.length }} photos
  </button>
</template>

No thumbnails on the page — the viewer fades in with the whole list.

<script setup lang="ts">
const props = defineProps<{ photos: { src: string, width: number, height: number }[] }>()

const route = useRoute()
const router = useRouter()
const viewer = useImageViewer()

onMounted(() => {
  const index = Number(route.query.photo)
  if (Number.isInteger(index))
    viewer.open(props.photos, index)
})

watch([viewer.isOpen, viewer.index], ([open, index]) => {
  router.replace({ query: open ? { photo: index } : {} })
})
</script>
/docs/customization/recipes

Scroll the photos: the address follows. Reload the page with ?photo=2 — it opens on that photo.

const viewer = useImageViewer()

viewer.open(productPhotos, 0, {
  bgOpacity: 1,
  closeOnVerticalDrag: false,
  ui: { counter: false, fullscreen: false },
})
:root {
  --image-viewer-bg: #fff;
  --image-viewer-color: #111;
  --image-viewer-button-bg: transparent;
  --image-viewer-button-bg-hover: rgb(0 0 0 / 0.06);
}

Bauhaus print

Giclée print on matte paper, 50 × 50 cm.

€49

A white, opaque viewer without a counter — and it doesn't close when you drag the image.

Labels from @nuxtjs/i18n

const { t } = useI18n()
const viewer = useImageViewer()

viewer.open(items, 0, {
  labels: {
    dialog: t('viewer.dialog'),
    close: t('viewer.close'),
    prev: t('viewer.prev'),
    next: t('viewer.next'),
  },
})

Fixed header that jumps when the page locks

Without scrollbar-gutter: stable on <html>, the page is padded by the scrollbar width while the viewer is open. Give your own fixed elements the same — or simply reserve the gutter:

html {
  scrollbar-gutter: stable;
}