HTML 属性:capture
capture
属性指定是否(可选)应捕获新文件,以及应使用哪个设备来捕获由 accept
属性定义的特定类型的新媒体。
值包括 user
和 environment
。capture
属性支持 file 输入类型。
如果 accept
属性指示输入应该是这些类型之一,则 capture
属性的值是一个字符串,用于指定用于捕获图像或视频数据的摄像头。
值 | 描述 |
---|---|
用户 |
应使用用户正面的摄像头和/或麦克风。 |
environment |
应使用面向外部的摄像头和/或麦克风。 |
注意:capture 之前是一个布尔属性,如果存在,则要求使用设备的媒体捕获设备(如摄像头或麦克风)而不是请求文件输入。
试一试
<label for="selfie">Take a picture of your face:</label>
<input type="file" id="selfie" name="selfie" accept="image/*" capture="user" />
<label for="picture">Take a picture using back facing camera:</label>
<input
type="file"
id="picture"
name="picture"
accept="image/*"
capture="environment" />
label {
display: block;
margin-top: 1rem;
}
input {
margin-bottom: 1rem;
}
示例
当在文件输入类型上设置时,具有麦克风和摄像头的操作系统将显示一个用户界面,允许从现有文件中选择或创建新文件。
html
<p>
<label for="soundFile">What does your voice sound like?:</label>
<input type="file" id="soundFile" capture="user" accept="audio/*" />
</p>
<p>
<label for="videoFile">Upload a video:</label>
<input type="file" id="videoFile" capture="environment" accept="video/*" />
</p>
<p>
<label for="imageFile">Upload a photo of yourself:</label>
<input type="file" id="imageFile" capture="user" accept="image/*" />
</p>
请注意,这些在移动设备上效果更好;如果您的设备是台式电脑,您很可能会看到一个典型的文件选择器。
规范
规范 |
---|
HTML 媒体捕获 # dfn-capture |
浏览器兼容性
加载中…