reactjs - 是否可以在所有内容之上实现全屏 react-dropzone,同时能够单击其下的元素?
问题描述
不确定这是否可能。很难理解冒泡是如何工作的。
解决方案
是的,这是可能的。
使用 CSS 调整字段的高度和大小,例如,将height
and设置width
为 dropzone 容器的 100%:
拖放区
import React, { Fragment } from "react";
import DropZone from "react-dropzone";
import { MdCloudUpload } from "react-icons/md";
import RenderImagePreview from "./renderImagePreview";
export default ({
handleOnDrop,
input,
imagefile,
meta: { error, touched }
}) => (
<div>
<DropZone
accept="image/jpeg, image/png, image/gif, image/bmp"
className="upload-container"
onDrop={handleOnDrop}
onChange={file => input.onChange(file)}
>
<div className="dropzone-container">
<div className="dropzone-area">
{imagefile && imagefile.length > 0 ? (
<RenderImagePreview imagefile={imagefile} />
) : (
<Fragment>
<MdCloudUpload style={{ fontSize: 100, marginBottom: 0 }} />
<p>Click or drag image file to this area to upload.</p>
</Fragment>
)}
</div>
</div>
</DropZone>
{touched && error && <div style={{ color: "red" }}>{error}</div>}
</div>
);
风格
.dropzone-container {
text-align: center;
background-color: #efebeb;
height: 100%;
width: 100%;
}
.dropzone-area {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.upload-container {
height: 100vh;
width: 100%;
margin-bottom: 10px;
}
ul {
list-style-type: none;
}
p {
margin-top: 0;
}
推荐阅读
- android - 无法为 /DCIM/Camera/.thumbnails 创建 .thumbs 目录
- wordpress - Wordpress:带有“关闭菜单”文本的白条出现在我的页脚下方并且无法删除
- asp.net - 拆分 ascx 文件以实现可维护性
- abap - cmd_ei_api=>maintain_bapi 更新 kna1 表字段 (ICMSTAXPAY)
- c# - C# 返回带有事件的对象
- javascript - 存储事件侦听器不在当前窗口上执行
- pandas - 以不同颜色绘制每年的年均值和标准差
- azure - Azure Kubernetes 服务节点池升级和补丁
- android - 尝试发送推送通知时出错
- javascript - flexbox 中的 p5.js 脚本