Requirements
- Toolset (Content Templates)
Directions
Add the CSS and JavaScript to a Toolset Content Template and add the template to a widget in the Footer. Add the HTML on the page where you would like to have a Masonic Image Gallery. Look at the comments in the code to see how to manipulate and adjust the masonic gallery to your liking.
Code
HTML
<div class="img-gall-cont">
<div class="img-gall-item"><img src="/wp-content/uploads/sites/4/2023/12/sky-414199-scaled.jpg" alt="Blue Sky with Sun Shining from Behind the Clouds Representing Sky is the Limit"></div>
<div class="img-gall-item"><img src="/wp-content/uploads/sites/4/2023/12/sailing-boat-1593613-scaled.jpg" alt="Sail Boats on the Ocean Representing the Wind Element"></div>
<div class="img-gall-item"><img src="/wp-content/uploads/sites/4/2023/12/forest-fire-432870-scaled.jpg" alt="Forest Fire Represinting the Fire Element"></div>
<div class="img-gall-item"><img src="/wp-content/uploads/sites/4/2023/12/fish-1839706-scaled.jpg" alt="Fish in the Ocean Representing the Water Element"></div>
<!-- More images -->
</div>
CSS
/* Masonic Image Gallery CSS */
.img-gall-cont {
width: 100%;
}
.img-gall-item {
max-width: 280px; /* Adjust this using % for the desired number of columns and px for responsive number of columns based on screen size */
width: 100%;
}
.img-gall-item img {
width: 100%;
height: auto;
display: block;
}
CSS
/*Masonic Image Gallery JavaScript*/
document.addEventListener('DOMContentLoaded', function() {
// Function to dynamically load the Isotope script
function loadIsotope() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://unpkg.com/isotope-layout@3.0.6/dist/isotope.pkgd.js'; // Updated URL
script.onload = initializeIsotope;
document.head.appendChild(script);
}
// Function to initialize Isotope
function initializeIsotope() {
var grid = document.querySelector('.img-gall-cont');
new Isotope(grid, {
itemSelector: '.img-gall-item',
percentPosition: true,
masonry: {
columnWidth: '.img-gall-item',
gutter: 0 /*Spacing in between columns*/
}
});
}
loadIsotope(); // Load and initialize Isotope
});