The video defined by the <video>
tag in html will automatically show its control bar and then hide the bar after several seconds every time it's loaded in the current window. But I'd like to cancel the automatically showing behavior, and make the control bar only appear when I hover on it. Any simple solution?
Here is an example: save the code to a html file, and every time you open it in the browser or switch to its tab from other tabs, the video control bar will automatically appear and disappear once.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="with=device-with initial-scale=1.0">
<style>
.video_preview::-webkit-media-controls-mute-button {
display: none;
}
.video_preview::-webkit-media-controls-volume-slider {
display: none;
}
.video_preview::-webkit-media-controls-current-time-display{
display: none;
}
.video_preview::-webkit-media-controls-time-remaining-display {
display: none;
}
</style>
<script>
$('#myvideo').hover(function toggleControls() {
if (this.hasAttribute("controls")) {
this.removeAttribute("controls")
} else {
this.setAttribute("controls", "controls")
}
})
</script>
</head>
<body>
<div>
<video id="myvideo" class="ha video_preview" width="20%" height="20%" muted="" autoplay="" loop="" controls="" controlslist="nodownload noremoteplayback noplaybackrate foobar" disablepictureinpicture="" src="http://www.computationalimaging.org/wp-content/uploads/2020/08/neuralholography_citl_holographic_display.mp4">Your browser does not support the video tag.</video>
</div>
</body>
</html>
I hope the video could behave like a gif image, and only show its control bar when I hover on it.
I tries the solution in https://stackoverflow.com/a/23280182/11140547 (adding the script to the <head>
as shown in above codes), but it failed in Chrome/Edge.