Jump to content

Re-initialize the gallery masonry grid via JS

Recommended Posts

Hi 👋

I have added a button to toggle the display of the captions for the masonry gallery using the following code.
 

<script>
$(function(){
  $('#block-yui_3_17_2_1_1686230394275_3985 a').on('click', function(event){
    event.preventDefault();
    $('.gallery-caption').toggle();
    if ($('#block-yui_3_17_2_1_1686230394275_3985 a').text() == 'Hide Captions') {
      $('#block-yui_3_17_2_1_1686230394275_3985 a').text('Show Captions')
    } else {
      $('#block-yui_3_17_2_1_1686230394275_3985 a').text('Hide Captions')
    }
  })
  $('.gallery-caption').hide();
  $('#block-yui_3_17_2_1_1686230394275_3985 a').text('Show Captions');
})
</script>

The toggle works, but I need to re-initialize the masonry grid to allow the captions to occupy space between the items. Does anyone know the code that will achieve this?

It must be used in the Squarespace code already, as the masonry grid will re-initialise if you change the browser's width.

Link to comment
  • Replies 0
  • Views 179
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • 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.