Jump to content

Gallery Captions & Padding between Images?

Recommended Posts

Site URL: https://smilodon-ocelot-my5f.squarespace.com/lost-america

Thanks to users on this forum, I've added gallery captions UNDER my galley images.

However, when scaling the site, the images can cover the caption above them.

Is there code to prevent this - maybe it needs percentage padding below the captions to override Squarespace's gallery settings?

passcode: trythis

 

 

 

(DESKTOP VIEW:)

 

1073900360_ScreenShot2020-04-23at11_11_44am.thumb.png.871f2f00e2fb1d72f4d1fa6050f8c4b9.png

 

 

 

(SCALED DOWN TO OTHER MEDIA:)

255063878_ScreenShot2020-04-22at6_26_52PM.png.cbd49ae3c24aab3c8a05b4d02a54d0f7.png.ccbfb89695890a4c5057de0124df6e8a.png

Link to comment
  • Replies 6
  • Views 537
  • Created
  • Last Reply
 
@media screen and (max-width: 767px){
	.gallery-grid--layout-grid .gallery-grid-wrapper {
		grid-row-gap: 3vw !important;
	}
}
Add this at the very bottom of the custom CSS.
Link to comment
  • 1 month later...

You can try adding the JavaScript code below which adjusts the height of the image containers to account for the caption height. Here's a video that shows a before and after when executing the code below:

 

JavaScript

(function (document) {
  var timeout;

  if (document.readyState === 'loading') {
    window.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }

  function init() {
    addNodeListForEachPolyfill();

    setTimeout(function () {
      handleMasonryItemsCaptions();
      triggerResizeEvent();
    }, 100);

    window.addEventListener('resize', function () {
      // If there's a timer, cancel it
      if (timeout) window.cancelAnimationFrame(timeout);

      // Setup the new requestAnimationFrame()
      timeout = window.requestAnimationFrame(handleMasonryItemsCaptions);
    });
  }

  function handleMasonryItemsCaptions() {
    var galleries = document.querySelectorAll('.gallery-masonry');

    if (!galleries) return;

    if (isDesktop()) {
      document.querySelectorAll('.gallery-masonry-item').forEach(function (item) {
        item.style.height = '';
      });
      return;
    }

    galleries.forEach(function (gallery) {

      var items = gallery.querySelectorAll('.gallery-masonry-item');

      items.forEach(function (item) {
        var height = 0;
        var wrapper = item.querySelector('.gallery-masonry-item-wrapper');
        var caption = item.querySelector('.gallery-caption');

        if (wrapper) {
          height += wrapper.offsetHeight;
        }

        if (caption) {
          caption.style.paddingBottom = 0 + 'px';
          height += caption.offsetHeight;
        }

        item.style.height = height + 'px';
      });
    });
  }

  function triggerResizeEvent() {
    var event;
    if (typeof (Event) === 'function') {
      event = new Event('resize');
    } else { /*IE*/
      event = document.createEvent('Event');
      event.initEvent('resize', true, true);
    }
    window.dispatchEvent(event);
  }

  function isDesktop() {
    return window.matchMedia('(min-width: 1024px)').matches;
  }

  function addNodeListForEachPolyfill() {
    if (window.NodeList && !NodeList.prototype.forEach) {
      NodeList.prototype.forEach = Array.prototype.forEach;
    }
  }

})(document);

Be sure the code above is between <script> tags, example:

<script>
  // Add JS code here
</script>

 

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.