我想创建一个library这样的砌体水平布局。它包含高度和宽度互不相同的图像集合。
只要符合以下条件,版式就可以包含一行或多行:
一行可以具有一个或多个列(图像),只要它满足以下条件:
这里是插图:
以下是“ Canva图片”标签的更真实示例:
我开始使用JavaScript(React Hook)对此进行编码,但是我坚持逻辑。
想象一下,许多具有不同尺寸的图像具有嵌入式块显示样式。对于这种情况,我目前的逻辑是:
当前进度的一部分
function Masonry({ minHeight, children }) {
const _originalDimension = [];
const _tempDimension = [];
children.forEach(({ props: { height, width } }) => {
const newWidth = (width / height) * minHeight;
const newHeight = minHeight;
_originalDimension.push({ height, width });
_tempDimension.push({ height: newHeight, width: newWidth });
});
const { container } = useStyles();
return (
<div className={container}>
{children.map((child, i) =>
cloneElement(child, { key: i, ..._tempDimension[i] })
)}
</div>
);
}
我无法确定行如何适合容器宽度以及行如何计算图像数量以适合最小或最大行高。
请帮助我,谢谢。