当前位置:网站首页>以两列的瀑布流为例,我们应该怎么构建每一列的数组
以两列的瀑布流为例,我们应该怎么构建每一列的数组
2022-07-03 03:56:00 【Attacking-Coder】
思路
往高度最小的那一列添加新的图片元素,直到它比另一列长了。此时就接着往短的那一列添加元素
代码(事例)
// data是包含瀑布流所有图片信息的数组
// numberOfColumns 代表的是瀑布流列数,咱们案例是2列
function classifyData(data: any[], numberOfColumns: number): any[] {
const result: any[] = [];
// 数组初始化
for (let i = 0; i < numberOfColumns; i++) {
result.push({
height: 0,
contents: []
});
}
data.forEach((item) => {
const minHeight = Math.min(...result.map((list) => list.height));
const minList = result.find((list) => list.height === minHeight);
// 这个函数的原则就是那一列短就往那一列后边补充数组
minList.contents.push(item);
minList.height += item.width === 0 ? 0 : item.height / item.width;
});
return result;
}
边栏推荐
- [Yu Yue education] reference materials of political communication science of Communication University of China
- Appium automated testing framework
- Arduino application development - LCD display GIF dynamic diagram
- Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
- Arlo's thinking about himself
- [learning notes] seckill - seckill project - (11) project summary
- What can learning pytorch do?
- How to move towards IPv6: IPv6 Transition Technology - Shangwen network quigo
- Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
- [DRM] simple analysis of DRM bridge driver call process
猜你喜欢

Appium automated testing framework

Ffmpeg download and installation tutorial and introduction

How to download pytorch? Where can I download pytorch?

Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange

【刷题篇】 找出第 K 小的数对距离

FileZilla Client下載安裝

Error in compiled file: error: unmapped character encoding GBK

在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
![[MySQL] the difference between left join, right join and join](/img/d4/8684cd59cd1bd77e70bd4d7c7074c3.jpg)
[MySQL] the difference between left join, right join and join

pytorch怎么下载?pytorch在哪里下载?
随机推荐
pytorch是什么?pytorch是一个软件吗?
leetcode:297. 二叉树的序列化与反序列化
Error in compiled file: error: unmapped character encoding GBK
navicat 导出数据库的表结构
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
[Blue Bridge Road - bug free code] pcf8591 - code analysis of AD conversion
Mongodb master profile
Hutool dynamically adds scheduled tasks
Captura下载安装及在Captura配置FFmpeg
Arduino application development - LCD display GIF dynamic diagram
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
CEPH Shangwen network xUP Nange that releases the power of data
2022年已过半,得抓紧
Hutool动态添加定时任务
@The difference between Autowired, @qualifier, @resource
【刷题篇】多数元素(超级水王问题)
ffmpeg录制屏幕和截屏
In Net 6 project using startup cs
NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr
Ffmpeg recording screen and screenshot