Created
August 7, 2018 12:59
-
-
Save mgibbs189/4264bdd3e3c5ac558aebce5a0408b719 to your computer and use it in GitHub Desktop.
FacetWP - Masonry with the layout builder?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resizeGridItem(item){ | |
grid = document.getElementsByClassName("fwpl-layout")[0]; | |
rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows')); | |
rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap')); | |
rowSpan = Math.ceil((item.querySelector('.fwpl-row').getBoundingClientRect().height+rowGap)/(rowHeight+rowGap)); | |
item.style.gridRowEnd = "span "+rowSpan; | |
} | |
function resizeAllGridItems(){ | |
allItems = document.getElementsByClassName("fwpl-result"); | |
for(x=0;x<allItems.length;x++){ | |
resizeGridItem(allItems[x]); | |
} | |
} | |
function resizeInstance(instance){ | |
item = instance.elements[0]; | |
resizeGridItem(item); | |
} | |
window.onload = resizeAllGridItems(); | |
window.addEventListener("resize", resizeAllGridItems); | |
allItems = document.getElementsByClassName("fwpl-result"); | |
for(x=0;x<allItems.length;x++){ | |
imagesLoaded( allItems[x], resizeInstance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment