reactjs - 使用 react js 以画廊格式显示图像
问题描述
我正在尝试在图像容器上显示多个图像。到目前为止,无论图像数量如何,图像都以相同的大小显示。如果图像是单个图像,我希望图像在容器中拉伸,并在多个图像的情况下调整大小并显示。
代码如下:
<>{post.postImagePath ?
<div className="postImage">
{
(post.postImagePath.split(',')).map((item,key)=>(<a href={
/user-post/${post.id}/${item}
} data-lightbox={image-user-${post.user.id}
} ><img src=
{/user-post/${post.id}/${item}
} key={key} style={{ width: '150px', height: '150px',objectFit:'cover',padding:'10px'}}/></a>)) }
{/*
<a href={post.postImagePath} data-lightbox={image-user-${post.user.id}
}
><img style={{ width: '100%', height: '300px',objectFit:'cover' }} src={post.postImagePath} /> </a>
<a href={imgString[0]} data-lightbox={
image-user-${post.user.id}
}
><img style={{ width: '100%', height: '300px',objectFit:'cover' }} src={imgString[0]} /> </a> */}
</div>
请让我知道如何实现这一目标。我也尝试过使用 react-image-gallery,但图像没有显示。
解决方案
推荐阅读
- asynchronous - Dart - 从 Stream Subscription 块返回数据
- node.js - Node.JS WebSocket 客户端内存泄漏
- python - 从列表中查找重复的 csv 列 [python pandas]
- node.js - TypeError:app.on 不是 Object 的函数。
- git - 合并 2 个分支后,git log 如何组织我的提交历史记录?
- reactjs - 如何将数据发送到最终表格
- linux - strace 没有显示完整的写入
- api - 如何做正确的休息api更新?
- html - 在 CSS 中结合悬停和之后的部署动画
- c++ - 为什么我的排名二叉搜索树实现如此缓慢?