Ways to position an image in the center and overlay it on a streaming webcam

Here is the current code I am working on:

window.addEventListener('load', function () {
                let selectedDeviceId;
                const codeReader = new ZXing.BrowserBarcodeReader()
                codeReader.getVideoInputDevices()
                    .then((videoInputDevices) => {
                        const sourceSelect = document.getElementById('sourceSelect')
                        selectedDeviceId = videoInputDevices[0].deviceId
    
                            codeReader.decodeFromInputVideoDevice(selectedDeviceId, 'video').then((result) => {
    window.location.href = 'https://www.example.com'
                            }).catch((err) => {
    window.location.href = 'https://www.example.com'
                            })
    
                    })
            })
html,body {
    margin:0;
    }
    body {
    padding:45px 0;
    background-image: url("https://i.imgur.com/A9J4iWz.png");
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-position: center;
    }
<!doctype html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Test Page</title>
    </head>
    
    <body>
        <video id="video" width="100%" height="100%"></video>
        <script type="text/javascript" src="https://pastebin.com/raw/STztkMyB"></script>
    </body>
    
    </html>

This page will display a live video from your webcam.

I tried to add an image overlay on the video using the following code, but it's not working as expected:

body {
    padding:45px 0;
    background-image: url("https://i.imgur.com/A9J4iWz.png");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
}

I also attempted to set z-index for the background image, however, that did not yield the desired results.

What could be causing the video to always appear on top?

Answer №1

Instead of trying to make the body element show in front of its content, you should add your image as its own element and overlay it on top of your video. Here's an example:

<div class="wrap">
  <video id="video"></video>
  <div class="overlay">
    <img src="https://i.imgur.com/A9J4iWz.png" alt="">
  </div>
</div>

.wrap {
  position:relative;
}

video {
  background-color: blue;
  width:100%;
  height:100%;
  z-index:15;
}

.overlay {
  position:absolute;
  top:0;
  width:100%;
  z-index:25;
  text-align:center;
}

img {
  display:inline-block;
}

You can adjust the positioning to achieve the desired look. Check out this fiddle for a demo: https://jsfiddle.net/2fu5woe3/2/

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

Interactive front end design for decision trees

On the front end, I aim to enable users to influence the outcome of a Decision Tree based on their selections. For my Django-React App, I have adopted the style and tree example from the codeplayer. You can find it here: I am tasked with creating an unor ...

Enhance the navbar brand with a unique lighting effect on the background

I'm currently working on a website and I'm interested in incorporating a lighting effect that resembles the one in the image linked below. I've been struggling to figure out where to begin and haven't been able to find any relevant info ...

Guide on altering UI presentation or modifying code in home automation system

https://i.sstatic.net/yxjcp.png Is there a way to customize the user interface or modify the code in home assistant? Has anyone had success with this before? Additionally, is it possible to integrate Visual Studio Code with home assistant? ...

Transform my sidebar menu into buttons for mobile and smaller screens

As a newcomer to bootstrap, I've been experimenting with converting my sidebar into a button for smaller screen sizes. I've managed to customize everything to fit my needs except for one thing. When the screen size is reduced (as on mobile devic ...

Condition-triggered Jquery Sticky navigation dynamically enables scrolling functionality

After successfully implementing a sticky navigation that works flawlessly, I am now looking to make it activate only when the browser width is less than or equal to 770px. This is my current code: $j = jQuery.noConflict(); $j(document).ready(function() ...

What is the best way to set this to display in line?

I'm in need of some assistance to troubleshoot an error I encountered while attempting to showcase a list in a single line, unfortunately it didn't work out as planned. #main-nav ul ul li { display: inline; } Despite setting the display to inli ...

Resizing Images in a Table with Proportional Scaling

I am working on a HTML table that has a width set to 100%. This table consists of two rows, each with two cells. Inside each cell, there is an image with a width of 100% and height set to auto, allowing the image to scale proportionally within the cell. H ...

Guidelines for Transmitting Form Data to Multiple PHP Files

I'm currently working on a Form within an HTML page that sends data to http://www.aaaaaa.com/1st-file.php. Here's an example of how the form is set up: <form action="http://www.aaaaaa.com/1st-file.php" method="post" enctype="plain" id="theFor ...

Modify a singular aspect of shorthand background attribute

Imagine using the shorthand background property to define multiple properties. For example: .img { background: url('/Content/images/a.png') no-repeat scroll 100% 3px; } If you need to override just the background-position of the image, sh ...

What is the most effective way to determine which radio button is currently selected in a group with the same name using JQuery?

<form class="responses"> <input type="radio" name="option" value="0">False</input> <input type="radio" name="option" value="1">True</input> </form> Just tested: $('[name="option"]').is(':checked ...

What is the reason behind the addition of escape characters to the hidden input value?

<body> <div> <?= $_POST['msg'] ?> </div> <form id="frm" method="post"> <input type="hidden" name='msg' value='{"field0": "Im a string", "field1": 84, "field3": "so am I"}' /> < ...

What is the process for inserting images into a vertical timeline format?

I am currently working on building a timeline and incorporating images into it. I came across a solution on W3 that I'm trying to implement, but I'm facing some challenges. I've been experimenting with the code but I feel like there are part ...

What issues arise when transitioning from PHP to JavaScript?

In my PHP code, I have a function that retrieves messages from the database. I want to set it up so that when a user clicks on a message, an alert will appear with the subject and body of the message using SweetAlert (I have already integrated SweetAlert). ...

Creating an event within a class that is generated dynamically when hovering

I'm trying to create a hover effect where an image moves around the page in a pattern (top left corner -> top right corner -> bottom right corner -> bottom left corner -> then back up to the top left corner). To achieve this, I am adding ...

Hiding the visibility of a table-cell will conceal the background color of its parent table row

In my coding project, I have implemented forms with a structure that utilizes display:table-row and display: table-cell. Previously, in Firefox 52, I was able to hide a cell element using visibility:hidden, effectively hiding the cell while maintaining the ...

What are the reasons why Bootstrap icons are not functioning properly in ReactJS?

I am facing an issue with bootstrap icons not working in ReactJS. Click here to view my buttons This is the code for my post items: import React from 'react'; const PostListItem = () => { return ( <li className="app-list ...

generate a flexible div that adjusts its height based on the size of the browser window

Is it possible to create a div layout structured like this: <div_wrapper> <div_header> </div_header> <div_content> </div_content> </div_wrapper> Upon page load, the div_header o ...

Use custom text in place of pagination numbers in the datatable

Is it possible to display the number of records on the page next to the page number, and have it change based on the number of records being shown? I apologize for any language errors. Example: from: [1][2][3][4][5][6] to: [1-10][11-20][21-30][31-40][41- ...

socket.io not defined and rejecting the connection

https://i.sstatic.net/B4bqV.pnghttps://i.sstatic.net/QfJqv.pngMy current code utilizes socket.io to display a message. However, when I execute node server.js, none of the output messages are being logged to the console. Below are snippets of my chat.html, ...

What is the functionality of Glyphicons and how can I create custom ones?

Currently, I have a collection of AI/SVG images that I've customized for use in an icon font library such as Glyphicons. Despite my efforts to find useful information through various sources, I haven't come across much helpful advice. One sugges ...