我怎样才能完全隐藏 HTML5 视频控件?
<video width="300" height="200" controls="false" autoplay="autoplay">
<source src="video/supercoolvideo.mp4" type="video/mp4" />
</video>
false 没有用——这是怎么做到的?
干杯。
像这样:
<video width="300" height="200" autoplay="autoplay">
<source src="video/supercoolvideo.mp4" type="video/mp4" />
</video>
controls
是一个布尔属性:
注意:布尔属性不允许使用值“true”和“false”。要表示假值,必须完全省略该属性。
您可以使用 CSS 伪选择器(如 Demo)隐藏控件:https ://jsfiddle.net/g1rsasa3
//For Firefox we have to handle it in JavaScript
var vids = $("video");
$.each(vids, function(){
this.controls = false;
});
//Loop though all Video tags and set Controls as false
$("video").click(function() {
//console.log(this);
if (this.paused) {
this.play();
} else {
this.pause();
}
});
video::-webkit-media-controls {
display: none;
}
/* Could Use thise as well for Individual Controls */
video::-webkit-media-controls-play-button {}
video::-webkit-media-controls-volume-slider {}
video::-webkit-media-controls-mute-button {}
video::-webkit-media-controls-timeline {}
video::-webkit-media-controls-current-time-display {}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<!-- Hiding HTML5 Video Controls using CSS Pseudo selectors -->
<video width="800" autoplay controls="false">
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4">
</video>
一个简单的解决方案是——只是忽略用户交互:-)
video {
pointer-events: none;
}
首先,删除视频的“控件”属性。
对于 iOS,我们可以通过添加以下 CSS 伪选择器来隐藏视频的内置播放按钮:
video::-webkit-media-controls-start-playback-button {
display: none;
}
有两种方法可以隐藏视频标签控件
从视频标签中删除该controls
属性。
将 css 添加到 video 标签
video::-webkit-media-controls-panel {
display: none !important;
opacity: 1 !important;}
<video width="320" height="240" autoplay="autoplay">
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
这种方法适用于我的情况。
video=getElementsByTagName('video');
function removeControls(video){
video.removeAttribute('controls');
}
window.onload=removeControls(video);
document.addEventListener("DOMContentLoaded", function() { initialiseMediaPlayer(); }, false);
function initialiseMediaPlayer() {
mediaPlayer = document.getElementById('media-video');
mediaPlayer.controls = false;
mediaPlayer.addEventListener('volumechange', function(e) {
// Update the button to be mute/unmute
if (mediaPlayer.muted) changeButtonType(muteBtn, 'unmute');
else changeButtonType(muteBtn, 'mute');
}, false);
mediaPlayer.addEventListener('ended', function() { this.pause(); }, false);
}