tips for preventing the automatic "pop-up and vanish" action of the HTML video control bar

Is there a way to prevent the control bar of a video defined by the <video> tag in HTML from automatically showing every time it's loaded in the current window? I want the control bar to only appear when I hover over the video. Any simple solutions?

For example, if you save the code to an HTML file and open it in a 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 want the video to behave like a gif image, showing its control bar only when hovered over.

I attempted a solution found on (adding the script to the <head> as indicated in the above code), but it didn't work in Chrome/Edge.

Answer №1

<!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>
        function video_show_control(obj)
        {
            if (!obj.hasAttribute("controls")) {
                obj.setAttribute("controls", "")
                }

        }
        function video_hide_control(obj)
        {       
            if (obj.hasAttribute("controls")) {
                    obj.removeAttribute("controls")
                    }
        }
        </script>

    </head>
    <body>
        <div>
         This is a sample video preview.
        </div>
        
        <div>
        <video id="myvideo" class="video_preview" width="40%" height="40%" muted="" autoplay="" loop=""  controlslist="nodownload noremoteplayback noplaybackrate foobar" disablepictureinpicture="" src="http://www.computationalimaging.org/wp-content/uploads/2020/08/neuralholography_citl_holographic_display.mp4" onmouseover="video_show_control(this)" onmouseout="video_hide_control(this)">Your browser does not support the video tag.</video>
        </div>
    </body>
</html>

This code functions properly without jquery.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Script execution is disabled on this system preventing the loading of content - ANGULAR V14

Every time I try to run my Angular project or any ng command, I keep encountering the following error message: ng : File C:\Users\achra\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this ...

The execution of JS code is being hindered by PHP codeigniter

Utilizing some pre-owned code in my current project The code snippet below is responsible for adding a product to the wishlist within the view <p class="p"><a<?php echo "onclick='addtowishlist($product->id)'"; ?>>Add To W ...

Using the chain method with Jquery's off() function

I can't figure out why my use of off() is not working properly. Is it trying to remove the class using removeClass() from document or #pager-next? $(document).off('click', '#pager-next').removeClass('disabled'); I want ...

Revealing an Angular directive's functionality to a different module

Imagine having a module with a directive structured as follows (this is a rough, untested implementation) There are 3 fundamental requirements that need to be fulfilled: Set up configuration for the element display Add event listeners accessible by the b ...

Continue looping in Javascript until an empty array is identified

Currently, I am in search of a solution to create a loop in Javascript that continues until the array of objects is empty. The object I am working with looks like this: "chain": { "evolves_to": [{ "evolves_to": [{ ...

Displaying Angular JS 1.5 component's HTML content in the browser as a commented-out section

Exploring the Angular world and facing a challenging issue with a basic angular component. My goal is to incorporate a custom element called "cast-tile" on the page, loaded by angular as a component. However, the browser seems to be treating the code in n ...

Node.js Discord Bot | Config File Manipulation for Improved Functionality

Currently, I am facing a challenge with understanding how my NodeJS bot can effectively read and write data to a config.json file. Additionally, I am unsure about how to identify arguments that are passed along with a Bot Command. With that in mind, I have ...

The footer fails to adhere to the bottom of the page

Struggling to keep my footer at the bottom of the page when there is minimal content. I attempted using: position:absolute; and bottom:0; It appears to stay in place, but when more content is added, it ends up going "under" the footer that remains n ...

What is the best way to make the sidebar occupy the entire space?

Learn about creating sticky footers using this method and check out an example here. * { margin:0; } html, body { height:100%; } #wrap { min-height:100%; height:auto !important; height:100%; margin:0 0 -47px; } #side { float:left; backgro ...

Eliminate all HTML code between two specific markers

Is there a way to effectively delete all the HTML content located between two specific strings on a webpage, regardless of their positions and the content in between them? For example, <div class='foo'> <div class='userid'& ...

Using React hook form to create a Field Array within a Dialog component in Material UI

I have a form with custom fields added via Field Array from react-hook-form, and everything is functioning properly. However, I recently implemented drag and drop functionality for the property items to allow reordering them. Due to the large number of fie ...

The readline interface in Node that echoes each character multiple times

After creating a node readline interface for my project, I encountered an unusual issue. this.io = readline.createInterface({ input: process.stdin, output: process.stdout, completer:(line:string) => { //adapted from Node docs ...

Exploring the functionality of the onblur HTML attribute in conjunction with JavaScript's ability to trigger a

How do the HTML attribute onblur and jQuery event .trigger("blur") interact? Will both events be executed, with JavaScript this.trigger("blur") triggering first before the HTML attribute onblur, or will only one event fire? I am using ...

I'm having trouble locating the source of the popstate loop that is generating numerous history entries

I am currently working on a project to create a dynamic webpage where the content of the main div gets replaced when certain navigation links are clicked. I have successfully implemented the pushstate function to update the div content and change the URL a ...

Ajax dependent dropdown is failing to load properly on the live server

My dropdown menus for country, state, and city are chained to each other, where the state options depend on the selected country and the city options depend on the selected state. While this functionality works perfectly on my local server, it's not w ...

Ensure confirmation dialog box pops up multiple times when deleting an item using AJAX

On my website, I have a side menu with multiple navigation items. In the admin section, there is a table where I can manage these items. The issue arises when I delete an item from the table using ajax - it gets deleted from both the table and the side men ...

The replace() function is failing to replace the provided inputs

Supposedly, when a user types in certain profanity and submits it, the word is supposed to be replaced with a censored version. Unfortunately, this feature is not working as expected. The word appears uncensored. Do you think implementing if/else stateme ...

Running Angular without dependencies causes it to malfunction

I recently ventured into the world of AngularJS and started by creating a module without any services or factories. Everything was running smoothly until I decided to introduce services and factories into my code. Suddenly, things stopped working. Here is ...

What is the method for determining the active configuration?

I am working with a MongoDB database that consists of 3 collections. Each collection is exemplified below by a document: tag _id: ObjectId('61b873ec6d075801f7a97e18') name: 'TestTag' category: 'A' computer _id: ObjectId(&apo ...

Having trouble pushing to an array in Angular typescript? It seems to be returning as undefined

As a newcomer to Angular with a basic understanding of JavaScript, I am attempting to create a program that can solve Sudoku puzzles. In a 9x9 grid, there are a total of 81 points or squares. To efficiently check for violations of Sudoku rules - no repeati ...