Skip to content

Images

Here are examples of how to use images with Fancybox and customize Panzoom instance that provides zoom and pan functionality.

Single image

If you don't want to create a gallery, use an empty data-fancybox attribute.

html
<a
  data-fancybox
  data-src="https://lipsum.app/id/1/1600x1200"
  data-caption="Hello world"
>
  <img src="https://lipsum.app/id/1/200x150" width="200" height="150" alt="" />
</a>
Sample image #1Sample image #1Sample image #1

Galleries are created by adding the same attribute data-fancybox value to multiple elements. For example, adding data-fancybox="gallery" attribute to multiple elements, will create a gallery from all these elements.

html
<a
  data-fancybox="gallery"
  data-src="https://lipsum.app/id/2/1600x1200"
  data-caption="Optional caption,&lt;br /&gt;that can contain &lt;em&gt;HTML&lt;/em&gt; code"
>
  <img src="https://lipsum.app/id/2/200x150" width="200" height="150" alt="" />
</a>

<a data-fancybox="gallery" data-src="https://lipsum.app/id/3/1600x1200">
  <img src="https://lipsum.app/id/3/200x150" width="200" height="150" alt="" />
</a>

<a data-fancybox="gallery" data-src="https://lipsum.app/id/4/1600x1200">
  <img src="https://lipsum.app/id/4/200x150" width="200" height="150" alt="" />
</a>

To create a gallery with a single preview image, simply create links for each item in the gallery, but only make one visible:

html
<a data-fancybox="gallery" href="https://lipsum.app/id/60/1600x1200">
  <img src="https://lipsum.app/id/60/200x150" width="200" height="150" alt="" />
</a>

<div style="display:none">
  <a data-fancybox="gallery" href="https://lipsum.app/id/61/1600x1200">
    <img src="https://lipsum.app/id/61/120x80" />
  </a>
  <a data-fancybox="gallery" href="https://lipsum.app/id/62/1600x1200">
    <img src="https://lipsum.app/id/62/120x80" />
  </a>
  <a data-fancybox="gallery" href="https://lipsum.app/id/63/1600x1200">
    <img src="https://lipsum.app/id/63/120x80" />
  </a>
</div>

JS Bin Example
JS Bin Example (using data attributes)

Cover mode

Create a "cover mode" effect using the minScale and maxScale options of Panzoom:

js
const options = {
  zoomEffect: false,
  showClass: "f-fadeIn",
  Carousel: {
    Thumbs: false,
    Zoomable: {
      Panzoom: {
        minScale: "cover",
        maxScale: "cover",
        wheelAction: "pan",
      },
    },
  },
};

Mouse panning

Use Panzoom's panMode option to enable "mouse panning". mouseMoveFactor specifies how much the mouse should be moved for the image to reach the border of the screen.

js
const options = {
  Carousel: {
    Thumbs: false,
    Toolbar: {
      display: {
        left: [],
        middle: [],
        right: ["close"],
      },
    },
    Zoomable: {
      Panzoom: {
        panMode: "mousemove",
        mouseMoveFactor: 1.1,
      },
    },
  },
};
Panning picture #1Panning picture #2Panning picture #3Panning picture #4