无法设置 React 网络摄像头高度
我尝试使用“%”(尝试从JS页面和CSS设置)设置网络摄像头高度。
<div>
{!imgSrc && <div>
<>
{/* className="video-stream" */}
<Webcam width={100 + '%'} // height={50 + '%'} does not work
audio={false}
ref={webcamRef}
screenshotFormat="image/jpeg"
// forceScreenshotSourceSize="true"
videoConstraints={{
...videoConstraints,
facingMode
}}
/>
</>
<Grid container={true} justifyContent='center' alignItems='center' spacing={1}>
<button onClick={capture}> Capture </button>
</Grid>
</div>}
CSS:
在CSS中,当我在像素中设置时,它可以在桌面上工作,但不能应用于移动设备。任何输入都将不胜感激。
用于移动和桌面:
@media only screen and (min-width: 360px) and (max-width: 750px) {
.video-stream {
height: 210px;
/* width: 290px; */
}
}
@media only screen and (min-width: 751px) {
.video-stream {
height: 400px;
/* width: 530px; */
}
}
I tried to set webcam height as below using '%' (tried setting both from js page and from css).
<div>
{!imgSrc && <div>
<>
{/* className="video-stream" */}
<Webcam width={100 + '%'} // height={50 + '%'} does not work
audio={false}
ref={webcamRef}
screenshotFormat="image/jpeg"
// forceScreenshotSourceSize="true"
videoConstraints={{
...videoConstraints,
facingMode
}}
/>
</>
<Grid container={true} justifyContent='center' alignItems='center' spacing={1}>
<button onClick={capture}> Capture </button>
</Grid>
</div>}
Css:
Here in css, when I set in pixel, it works on desktop but doesn't get applied for mobile. Any input would be appreciated.
For mobile and desktop:
@media only screen and (min-width: 360px) and (max-width: 750px) {
.video-stream {
height: 210px;
/* width: 290px; */
}
}
@media only screen and (min-width: 751px) {
.video-stream {
height: 400px;
/* width: 530px; */
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以向网络摄像头组件添加 className 并在 css 文件中使用 %,然后根据需要将像素大小添加到父元素。例如,如果我将网络摄像头组件包装在 div 元素中,它可能类似于:
在 css 文件中:
You can add a className to the Webcam component and use % in the css file, then add the pixel size to a parent element according to your needs. For example if I wrap the Webcam component in a div element it can be something like:
in the css file: