How it works

How the effect is put together.

The magnify() function

  • magnify(imgID, overlay) adds the frame to an overlay element and sets the overlay's background to the data-img image, scaled to the photo's size.
  • On mousemove and touchmove, the overlay follows the pointer and stays inside the photo.
  • The overlay's background shifts with it, so the hidden image lines up exactly with the photo underneath.

The lens shape

A CSS mask-image cuts the overlay to the shape of the lenses, so only the area inside the glasses shows the second image.

Contribute

Improvements are welcome: open an issue or pull request on GitHub.

Something unclear or missing? Tell us.