css - How to make Image gallery Layout like Pexels.com?
问题描述
I am trying to make a dynamic image gallery with help of Pexels API. How to make the Layout like https://pexels.com using CSS.
Currently, I made 3 columns. but If there were lots of images to load dynamically. It won't work as I am expecting.
I am using React framework and rendering images with help of this logic.
useEffect(() => {
// data is responded from APIs
if (data) {
const { pages } = data;
const newArr = cols;
let counter = 0;
const paginate = pages[pages.length - 1];
while (paginate.photos.length) {
// filling each col like this.
newArr[counter].push(...paginate.photos.splice(0, 3));
counter = counter == 2 ? 0 : counter + 1; // 3 cols only
}
setCols([...newArr]);
}
}, [data]);
I am looking for a little robust solution
解决方案
推荐阅读
- excel - 在 VBA 中使用 ADODB SQL,为什么只有当我使用分组时,字符串才会被截断 [到 255]?
- react-native - 为什么在组件卸载后反应原生不释放内存?
- ssis - SSIS 错误“要在 SQL Server Data Tools 之外运行 SSIS 包,您必须安装标准版的 Integration Services 或更高版本”
- css - 将div的宽度设置为封闭表格的宽度
- php - 无法在 .htaccess 中正确重写和重定向 url
- ruby-on-rails - 为什么我的 Slack 应用程序只发布临时消息?
- angular - 缓存整个页面时如何打破Service Worker的生命周期?
- types - 在函数 f(a::T, x::T) 中混合 Real 和 Complex{Real},其中 T <: Union{Real, Complex{Real}}
- java - FileNotFoundException 的 catch 内嵌套 try-catch IOException
- powerbi - 使用 DirectQuery Power BI 时替换计算列中的 MAXX