javascript - 将捕获按钮添加到捕获窗口的底部中心
问题描述
我正在使用 react-webcam npm 库,目前,“捕获图像”按钮位于屏幕底部,如图所示。 捕获按钮默认位置
我想要做的是将该按钮放在捕获窗口的底部中心,如我在此处显示的那样。 需要添加捕获按钮的区域
这是我的相机和按钮
<Webcam
audio={false}
ref={webcamRef}
screenshotFormat="image/jpeg"
style={{ height: 600, width: "100%" }}
/>
<button
onClick={capture}
style={{marginTop: "-200px"}}
>
Capture photo
</button>
我试过给 marginTop 和 marginBottom 但无法完成。知道如何解决这个问题吗?
解决方案
您需要一个可以包装按钮的容器来给它一个绝对位置:
//style.css
.video-container {
position: relative;
}
.button {
position: absolute;
top: 90%;
left: 50%;
transform: translate(-50%, 0%);
}
//你的jsx
<div
className="video-container"
style={{ height: '600px', width: "100%" }}
>
<Webcam
autoPlay
style={{ height: '100%', width: "100%" }}
audio={false}
ref={webcamRef}
screenshotFormat="image/jpeg"
/>
<button className="button" onClick={capture} >Capture photo</button>
</div>
演示:https ://codesandbox.io/s/strange-ardinghelli-mss9c?file=/src/index.js:0-42
推荐阅读
- javascript - 如何在 JS 字符串中保留 HTML 实体?
- mongodb - 为什么 mongodb Enterprise 4.4.0 中缺少 mongostat 可执行文件?
- javascript - 如何将 XMLHttpRequest 与开放层一起使用
- django - Django REST Framework 在文件之间共享类实例
- dataframe - 从 txt 文件中读取数据并存储在数据框中
- angular - Angular 8 - 表单构建器中的 For 循环
- kotlin - 使用默认参数不向函数传递值
- php - PHP数组获取父项值
- r - 在 RMarkdown 的 pander 表中渲染上标
- reactjs - 错误:元素类型无效:应为字符串或类/函数,但得到:未定义。导入错误