Skip to content

Instantly share code, notes, and snippets.

@Darkproduct
Last active April 11, 2023 14:24
Show Gist options
  • Save Darkproduct/36e354bec1eedf8c8dcfb0c73cf26a51 to your computer and use it in GitHub Desktop.
Save Darkproduct/36e354bec1eedf8c8dcfb0c73cf26a51 to your computer and use it in GitHub Desktop.
Simple Image Gallery Overlay

A simple image gallery overlay which should work an any blog without needing to change anything else.

image The overlay is fullscreen and shows one image at a time. The controlls are:

  • Button at the top and bottom to quit, or press Escape or q
  • Button on the left side Arrow left or a to go to the previous image
  • Button on the right side Arrow right or d to go to the next image

It also is assumed, that the img_filter, which can be set at the top of the JavaScript finds all <img> tags which should be included. Additionally, each <img> tag should be contained in a single container. Because this copies the content of the parent to work properly with images that have a <source> tag.

A typical image I want to include looks something like this in HTML:

<picture class="picture-wrapper">
  <source srcset="/images/image_500x0_resize_q90_box.jpg 500w, /images/image_800x0_resize_q90_box.jpg 800w" type="image/jpeg">
  <source srcset="/images/image_500x0_resize_q90_h2_box.webp 500w, /images/image_800x0_resize_q90_h2_box.webp 800w" type="image/webp">
  <img loading="lazy" src="/images/image_1500x0_resize_q90_box.jpg" class="figure-img img-fluid" alt="alt" width="1500" height="1125">
</picture>

And I also have this css:

.img-fluid {
    object-fit: contain;
    width: 100%;
    height: 100%;
}

I wrote this for Hugo with hugo-responsive-images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment