Gallery✨ Premium

Product Zoom

Product gallery: thumbnails change the large photo on hover, click, tap or keyboard, and the large photo zooms twice under the pointer.

JSE-commerce

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Gallery has 44 effects, including 6 free. Explore the category →

3 usage examples

Sofa colours — hover a shade, then the weave — Product Zoom example 1

① Sofa colours — hover a shade, then the weave

WhenOn the Ondelin sofa page at Maison Calvérine, four thumbnails under the photo show terracotta, sage green, midnight blue and linen. The visitor hovers a shade, the large photo changes and the colour name follows; then they move onto the photo to see the fabric weave.
WhyPicking a colour and checking the material happen in the same frame, without opening a viewer: that is the expected gesture on a furniture page.
Settings--pdz-width: 310px, --pdz-ratio: 7/4, --pdz-thumb: 73px, --pdz-thumb-ratio: 4/3, --pdz-accent: #2b2420, --pdz-zoom: 2.2. The scene shows the colour name by reading aria-pressed.
Prescriptions to prepare in pharmacy software — click, then read the dosage — Product Zoom example 2

② Prescriptions to prepare in pharmacy software — click, then read the dosage

WhenIn Frelandine, order #2207 for collection tomorrow lists three prescriptions; the right-hand panel shows them as thumbnails. The pharmacist clicks a prescription (the matching row lights up), then hovers the large view to read the dose and length of each medicine.
WhyA prescription is checked line by line, in small print: the gallery fits in a narrow side panel next to the list, and the zoom saves opening each scan in a new tab.
Settings--pdz-width: 196px, --pdz-ratio: 24/25, --pdz-thumb: 58px, --pdz-zoom: 2.4, --pdz-accent: #5b5bd6. In the capture, the scene clicks the thumbnails one after another.
One-, two- and three-bedroom plans of a housing development — Product Zoom example 3

③ One-, two- and three-bedroom plans of a housing development

WhenOn the Les Hautes Brémondes site, the plan fills the left and three thumbnails labelled T2, T3 and T4 are stacked on the right, above the “Request a call” button. Hovering a layout shows its plan; hovering the plan enlarges each room's area.
WhyThe visitor compares homes: switching plans on hover is quick, and reading “Bedroom 2 — 10.4 m²” takes the zoom.
SettingsGallery in a row (.pdz-gallery{flex-direction: row}, thumbnails in a column), --pdz-ratio: 7/5, --pdz-thumb: 112px, --pdz-accent: #1d8a6f, --pdz-zoom: 2; a label added inside each button.

How it works

The large photo .pdz-frame and the .pdz-thumb thumbnails are real tags: an <img> for the large one, a <button> wrapping an <img> for each thumbnail. Choosing a thumbnail (mouse hover, click, tap or keyboard focus) copies its image into the large photo, or the file in its data-zoom-src if there is one, together with its alt text. The chosen thumbnail switches to aria-pressed="true" and the large photo gives a short 110% pulse for 0.3 s.

The zoom: while the mouse or a finger is on the large photo, the is-zoomed class enlarges it to --pdz-zoom (2) and the target point becomes the zoom origin, like a magnifier following the pointer. On leaving, the photo is whole again.

Every lookup starts from the .fx-0185-root: two galleries on a page each keep their own large photo without driving each other, and the script can be pasted twice.

Accessibility

  • Thumbnails: real buttons, reached with Tab, named by their image's alt text, with aria-pressed telling which one is shown. Focus alone changes the photo.
  • Keyboard zoom: the large photo takes Tab focus and zooms on its centre; arrow keys shift the area by 5% (20% with Shift), Escape shows the whole photo again.
  • Touch: tapping a thumbnail changes the photo; putting a finger on the large photo and dragging zooms and pans, lifting it shows the whole photo again (touch-action: none on the large photo only). A single tap does not leave the photo enlarged.
  • Reduced motion: under prefers-reduced-motion: reduce, no pulse and no sliding; the zoom is applied at once.

Browser compatibility

HTML buttons, Pointer Events, CSS transforms, aspect-ratio and 3 KB of JavaScript, no dependency. Measured in Chromium 151, Firefox 153 and WebKit 26.5: two independent galleries (hovering the 2nd no longer touches the 1st), script pasted twice without error, thumbnails with Tab, a real tap and drag at 390 px (Chromium).

Chrome 88+✓ Full (measured)
Firefox 89+✓ Full (measured)
Safari 15+✓ Full (WebKit engine measured)
Edge 88+✓ Full (Chromium engine)
Mobile iOS 15+✓ Full (WebKit engine measured)
Android Chrome 88+✓ Full (Chromium engine)

Without JavaScript, the large photo and thumbnails show, with no switching or zoom. In Safari, Tab only reaches buttons when “Press Tab to highlight each item” is on.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0185-root">
  <div class="pdz-gallery">
    <div class="pdz-frame" tabindex="0" role="group" aria-label="Product photo: hover it, drag a finger or use the arrow keys to zoom in">
      <img class="pdz-image" src="view-1-large.jpg" alt="Front view">
      <span class="pdz-label" aria-hidden="true">Product View</span>
    </div>
    <div class="pdz-thumbs" role="group" aria-label="Product variants">
      <button type="button" class="pdz-thumb" aria-pressed="true"><img src="view-1.jpg" data-zoom-src="view-1-large.jpg" alt="Front view"></button>
      <button type="button" class="pdz-thumb" aria-pressed="false"><img src="view-2.jpg" data-zoom-src="view-2-large.jpg" alt="Back view"></button>
      <!-- as many thumbnails as needed -->
    </div>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Images (HTML — thumbnails and large photo) 4 colour patterns (inline SVG) One thumbnail = one <button class="pdz-thumb"> with its <img>. data-zoom-src on a thumbnail's image gives the large version shown and zoomed. Put the same image in .pdz-image to start with.
--pdz-zoom 2 Enlargement of the large photo under the pointer.
--pdz-width · --pdz-ratio · --pdz-radius 280px · 7 / 4 · 0.75rem Maximum width, proportions and rounding of the large photo (and of the gallery).
--pdz-thumb · --pdz-thumb-ratio 60px · 4 / 3 Thumbnail size and shape.
--pdz-accent #6366f1 Border of the chosen or hovered thumbnail.
.pdz-label caption “Product View” Text centred on the large photo, hidden while zoomed; remove it on real photos.

FAQ

On the large photo: hover it (or put a finger on it, or give it focus) and it enlarges twice around the target point. The thumbnails pick the photo.
Yes: data-zoom-src on a thumbnail's image. The thumbnail stays light and the large photo loads the big file when it is chosen.
Yes: remove the pointerenter listener from the script. Click, tap and keyboard keep working.