parent
d5c31f0d0b
commit
1bcc181220
6 changed files with 101 additions and 79 deletions
@ -0,0 +1,23 @@ |
|||||||
|
function resizeItem(masonry, item){ |
||||||
|
let rowHeight = parseInt(window.getComputedStyle(masonry).getPropertyValue('grid-auto-rows')); |
||||||
|
let rowGap = parseInt(window.getComputedStyle(masonry).getPropertyValue('grid-row-gap')); |
||||||
|
let rowSpan = Math.ceil((item.querySelector('.masonry-item-content').getBoundingClientRect().height+rowGap)/(rowHeight+rowGap)); |
||||||
|
item.style.gridRowEnd = "span "+rowSpan; |
||||||
|
} |
||||||
|
|
||||||
|
function resizeAll(){ |
||||||
|
let masonry = document.getElementsByClassName("masonry")[0]; |
||||||
|
masonry.style.gridAutoRows = "20px" |
||||||
|
masonry.style.marginBottom = "80px" |
||||||
|
let allItems = document.getElementsByClassName("masonry-item"); |
||||||
|
|
||||||
|
for (const item of allItems) { |
||||||
|
resizeItem(masonry, item) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
window.addEventListener("load", () => { |
||||||
|
resizeAll() |
||||||
|
|
||||||
|
window.addEventListener("resize", resizeAll); |
||||||
|
}) |
@ -0,0 +1,11 @@ |
|||||||
|
.masonry { |
||||||
|
display: grid; |
||||||
|
grid-gap: 20px 90px; |
||||||
|
grid-template-columns: repeat(2, minmax(250px, 1fr)); |
||||||
|
// grid-auto-rows: 20px; // Set by JavaScript |
||||||
|
// margin-bottom: calc(4 * 20px); // Set by JavaScript |
||||||
|
|
||||||
|
@media #{$media-size-medium} { |
||||||
|
grid-template-columns: 1fr; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue