Placing buttons on top of a video within a div container

I am facing a challenge with implementing custom controls on a video embedded in my webpage. I have tried setting a div to absolute position for the buttons, but they are not clickable.

Is there a way to achieve this without using jQuery? I need the buttons in the div to be both visible and clickable above the video.

Embedded Video:

<div id="divVideo" style="text-align:center"> 
<video id="video1" width="720" autoplay loop>
<source src="01_vid.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
Your browser does not support HTML5 video.
</video>
</div>

Custom Buttons (with associated script):

<button type="button" onclick="playPause(this)" class="btn btn-primary">&#9646;&#9646</button>
<button type="button" onclick="muteUnmute(this)" class="btn btn-primary">Mute</button>
<button type="button" onclick="goHD(this)" class="btn btn-primary">HD</button>

Javascript Functions:

var myVideo = document.getElementById("video1"); 

function playPause(btn) { 
if (myVideo.paused) {
    myVideo.play(); 
    btn.innerHTML = "&#9646;&#9646"
} else {
    myVideo.pause();
    btn.innerHTML = "&#9658"
}
} 

function muteUnmute(etc) { 
if (myVideo.muted) {
    myVideo.muted = false
    etc.innerHTML = "Mute"
}   else {
    myVideo.muted = true; 
    etc.innerHTML = "Unmute"
} 
}

function goHD(el)   {
if (myVideo.width != 1280){
    myVideo.width = 1280
    el.innerHTML = "SD"
    }
else{
    myVideo.width = 720
    el.innerHTML = "HD";
}
}

CSS Styles:

#botoes {
float: center;
position: absolute;
bottom: 0; z-index: 1; 
width: 100%; 
text-align: center;
margin-bottom: 10px;
}
#divVideo {
position: relative;
width: 720px;
float: left;
height: 405px;
}
#video {
position: relative;
width: 720px;
height: 405px;
background-color: blue;
float: left;
display: block;
}

How can I ensure that the custom control buttons appear above the video within the containing div?

Answer №1

Unfortunately, I am unable to display a realistic video at this moment. Please visualize the image as if it were a video.

.video {position: relative; width: 350px;}
.video img {display: block;}
.video .buttons {position: absolute; bottom: 0; z-index: 1; width: 100%; text-align: center;}
<div class="video">
  <img src="http://placehold.it/350x150" />
  <div class="buttons">
    <button type="button" onclick="playPause(this)" class="btn btn-primary">&#9646;&#9646</button>
    <button type="button" onclick="muteUnmute(this)" class="btn btn-primary">Mute</button>
    <button type="button" onclick="goHD(this)" class="btn btn-primary">HD</button>
  </div>
</div>

If you desire for the buttons to only appear when hovering your mouse over the video, follow these instructions:

.video {position: relative; width: 350px;}
.video img {display: block;}
.video .buttons {position: absolute; bottom: 0; z-index: 1; width: 100%; text-align: center; display: none;}
.video:hover .buttons {display: block;}
<div class="video">
  <img src="http://placehold.it/350x150" />
  <div class="buttons">
    <button type="button" onclick="playPause(this)" class="btn btn-primary">&#9646;&#9646</button>
    <button type="button" onclick="muteUnmute(this)" class="btn btn-primary">Mute</button>
    <button type="button" onclick="goHD(this)" class="btn btn-primary">HD</button>
  </div>
</div>

Answer №2

video {
  width: 300px;
  height: auto;
}
div {
  background: rgba(255, 255, 255, .85);
  height: 50px;
  width: 500px;
  position: relative;
  top: -50px;
  padding: 5px;
}
<video id="video" controls="" preload="none" mediagroup="myVideoGroup" poster="http://media.w3.org/2010/05/sintel/poster.png">
  <source id="mp4" src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4" />
  <source id="webm" src="http://media.w3.org/2010/05/sintel/trailer.webm" type="video/webm" />
  <source id="ogv" src="http://media.w3.org/2010/05/sintel/trailer.ogv" type="video/ogg" />
  <p>Your browser does not support the HTML5 Video element.</p>
</video>
<div>
  <button>Play</button>
  <button>Stop</button>
</div>

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

Exploring the usage of multidimensional arrays in React components

How can I extract data such as teamId from the "teams" array using datas.map() method in a multidimensional array? Any tips or help would be appreciated. Is there another way to map out this data? { "gameId": 3226262256, "platformId": "NA1", " ...

Enhance the functionality of jqGrid by customizing key bindings for arrow and tab keys

In order to enhance my jqGrid functionality, I am seeking to implement the ability for users to press different keys for specific actions. For example, pressing Enter should save data (which is currently working fine), while pressing the left arrow key sho ...

After the build process, Nextjs Sitemap is eliminating the /en/ from all newly generated web links

Utilizing Strapi to pull data in JSON format. For instance, a typical website link appears as follows: https:/ /www.some-site.com/some-link What happens to the links once the post build is completed on my Nextjs project: <url><loc>https://web ...

A Guide to Setting the HTML Lang Attribute on a Specific Page in Next.js

I have a website built with Next.js that consists of several pages. Most of the pages are in English, but there is one page that is in French and does not have an English version. How can I assign the lang attribute to the HTML tag for this specific page ...

What is the best way to bypass TS1192 when incorporating @types/cleave.js into my Angular application?

Using cleave.js (^1.5.2) in my Angular 6 application, along with the @types/cleave.js package (^1.4.0), I encountered a strange issue. When I run ng build to compile the application, it fails and shows the following errors: ERROR in src/app/app.component. ...

Exploring the attributes and functions of JavaScript Objects in an Angular environment

Can Angular's $http.post method recognize JavaScript object properties when sending data? To understand more about JavaScript objects and their properties, visit https://www.w3schools.com/js/js_objects.asp. Here is an example to illustrate my questio ...

modifying Redux state according to the position in an array

In my food truck app, I have stored customer orders in the redux state as an array of objects. Each order includes a list of items selected by the customer, along with the count, name, and total price for each item. For example: state.order = [ {item: " ...

Tips for avoiding flickering in a background image when it is being changed

Utilizing JavaScript, I am setting a repeated background image from a canvas to a div in the following way: var img_canvas = document.createElement('canvas'); img_canvas.width = 16; img_canvas.height = 16; img_canvas.getContext('2d' ...

Implementing Twain functionality in an Electron-based desktop application

I've been tasked with building a desktop application using React + Electron, and my client wants to incorporate scanning documents using a scanner and uploading them to the server through the app. Are there any effective ways to integrate Twain into R ...

I attempted to separate a string containing <br> tags using the explode function, but the method was not successful

In my code, there is a string that looks like this <br> ACCEPT:YES <br> SMMD:tv240245ce <br> This string is stored in a variable called $_session['result'] My task is to extract the following information either as an array or ...

Kendo Grid with locked height

Using a grid with some elements locked, we have established a CSS-defined minimum and maximum height for the grid. .k-grid-content { max-height: 400px; min-height: 0px; } An issue arises when setting the height of the locked grid. If the grid&a ...

Eliminate Video Time Indicator

Can the video progress bar be removed from this specific video player? I would like it to be integrated into the embed code that I share with others. <iframe id="hapyak-player-157199-8825" marginwidth="0" marginheight="0" frameborder="no" scrolling=" ...

The value property of the input element is returning as undefined

The input value entered is always returning undefined. Despite trying various solutions found in similar questions, my jQuery code continues to return undefined. jQuery: $( document ).ready(function() { $('#Input').keypress( function(e ...

Uncovering unseen glitches while coding in Vue.js

After changing the page, I noticed that the errors from the form are still visible. Is there a way to make them disappear when navigating away and only show up if I return to the page? Here are the errors I am encountering: <template> <b-form @ ...

The PHP SDK function works flawlessly in the local host environment and in console, however, it fails to perform on the browser when deployed

My PHP function is behaving differently between the server's command line and the web page, with successful execution on a local WAMP host. Any thoughts on what could be causing this inconsistency? function getCFTemplateSummary($CFUrl){ //init client ...

How can I retrieve the height of a dynamically generated div in Angular and pass it to a sibling component?

My setup consists of a single parent component and 2 child components structured as follows: Parent-component.html <child-component-1 [id]="id"></child-component-1> <child-component-2></child-component-2> The child-compo ...

The CSS style tag does not function in Safari

I am trying to dynamically load background images using CSS based on the display resolution using the @media keyword. This method works perfectly in Firefox and Chrome, but unfortunately, it does not seem to work in Safari. Is there something I might be ...

When working with AngularJS, I noticed that the service function within a loop is only executed after all iterations have been completed

Controller Page $scope.page = { '1' : "small", '2' : "large", '3': "medium" }; $scope.form.appraisal_id = "abc123"; $scope.form.user_id = "efg123"; for(var prop in $scope.page ...

Why isn't my script responding to mouse events like mouseenter, mouseover, or any other mouse event?

const element = document.getElementById("box"); element.addEventListener("mouseenter", handleMouse); function handleMouse(event) { console.log("Event type: " + event.type); } ...

What exactly does the .proxy() method do in jQuery?

Can you explain the purpose of the jQuery.proxy function in jQuery and describe the scenarios where it is most beneficial? I came across this link, but I'm struggling to grasp its concept fully. ...