Is there a way to adjust the orientation of a <video> element without affecting the orientation of the video controls?

<video controls>
</video>
video {
 transform: scaleX(-1)
}

This CSS code flips the video horizontally, but it also flips the control buttons along with it.

I attempted to flip the wrapper element containing the video using .wrapper {transform: scaleX(-1), but it did not solve the issue.

Since I am not proficient in creating custom video controls from scratch, I am seeking a solution that involves only CSS like transform: scaleX().

How can I achieve a mirrored effect on the video itself while keeping the control buttons unaffected?

MIRRORED IMAGE https://i.sstatic.net/s6MVV.jpg

UNMIRRORED IMAGE https://i.sstatic.net/huksK.jpg

Answer №1

If you're looking for a simple solution, you can hide the default video controls, flip the video horizontally, and create your own custom controls. Below is a basic example that you can modify to suit your needs.

const video = document.getElementById('videoPlayer');
const playPauseButton = document.getElementById('playPause');
const muteToggleButton = document.getElementById('muteToggle');
const fullscreenToggleButton = document.getElementById('fullscreenToggle');
const progressBarContainer = document.getElementById('progressBarContainer');
const progressBarFilled = document.getElementById('progressBarFilled');
const timeDisplay = document.getElementById('timeDisplay');

function togglePlayPause() {
  if (video.paused) {
    video.play();
    playPauseButton.textContent = 'Pause';
  } else {
    video.pause();
    playPauseButton.textContent = 'Play';
  }
}

function toggleMute() {
  video.muted = !video.muted;
  muteToggleButton.textContent = video.muted ? 'Unmute' : 'Mute';
}

function toggleFullscreen() {
  if (!document.fullscreenElement) {
    video.requestFullscreen();
  } else {
    document.exitFullscreen();
  }
}

function updateProgressBar() {
  const percentage = (video.currentTime / video.duration) * 100;
  progressBarFilled.style.width = percentage + '%';
  updateTimerDisplay();
}

function seek(e) {
  const newTime = (e.offsetX / progressBarContainer.offsetWidth) * video.duration;
  video.currentTime = newTime;
}

function updateTimerDisplay() {
  const formattedCurrentTime = new Date(video.currentTime * 1000).toISOString().substr(14, 5);
  const formattedDuration = new Date(video.duration * 1000).toISOString().substr(14, 5);
  timeDisplay.textContent = `${formattedCurrentTime} / ${formattedDuration}`;
}

playPauseButton.addEventListener('click', togglePlayPause);
muteToggleButton.addEventListener('click', toggleMute);
fullscreenToggleButton.addEventListener('click', toggleFullscreen);
progressBarContainer.addEventListener('click', seek);
video.addEventListener('timeupdate', updateProgressBar);
.video-container {
  position: relative;
  width: 100%;
  max-width: 640px;
}

.video-container video {
  transform: scaleX(-1);
  width: 100%;
  height: auto;
}

.video-controls {
  position: absolute;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  width: 100%;
  display: flex;
  align-items: center;
  padding: 5px -5px 5px 5px;
}

.video-controls button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  margin-right: 10px;
}

.progress-bar-container {
  flex-grow: 1;
  cursor: pointer;
  margin-right: 10px;
}

.progress-bar {
  width: 100%;
  height: 5px;
  background: #666;
  position: relative;
}

.progress-bar-filled {
  background: #fff;
  height: 100%;
  width: 0;
}

.time {
  font-size: 0.8em;
  margin-right: 10px;
}
<div class="video-container">
  <video id="videoPlayer">
    <source src="https://uce23327b0bab5175c1c0c0cbc0a.dl.dropboxusercontent.com/cd/0/inline/CJhjJhXufoSbuAopjZ-4fWNFBDaEyp-tZ_08YeqLy-avay9VQ4coVwwdsfHZWhB9S7W6oOzxpx-e2R6Mj5Fa1QzbkumZOHOlNhHpud84YbApN3-tZHbuLrCQgakMIQ6YQRlu6I2GrK_UwdAqmaEdELw6/file#" type="video/mp4">
    Your browser does not support the video tag.
  </video>
  <div class="video-controls">
    <button id="playPause">Play/Pause</button>
    <button id="muteToggle">Mute/Unmute</button>
    <button id="fullscreenToggle">Fullscreen</button>
    <div class="progress-bar-container" id="progressBarContainer">
      <div class="progress-bar">
        <div class="progress-bar-filled" id="progressBarFilled"></div>
      </div>
    </div>
    <div class="time" id="timeDisplay">00:00 / 00:00</div>
  </div>
</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

Focusing in on a PARTICULAR SECTION of the picture

My website has a unique concept - comparing two articles side by side. One of the articles is mine, while the other is displayed alongside it. To capture entire pages for comparison, I utilize Google's GoFullPage feature to take screenshots. The goa ...

What is the best way to ensure that the child element of a Material UI TableCell Component occupies the full height of the cell?

I am currently using MUI version 5 to create a table. In this table, there are two columns with cells that contain multiline TextFields. My goal is to have the TextFields completely fill the cell area. However, I am encountering an issue where when I start ...

Using HTML and CSS to evenly align text in individual sections

Is it possible to recreate the exact look and feel of a justified page from a book or article online using HTML/CSS? This would include replicating the text justification with precise line breaks and setting the outer wrapper width to match the min/max-wid ...

Mastering the Art of Scrolling

Can someone please tell me the name of this specific scrolling technique? I am interested in using something similar for my project. Check out this example site ...

Effortless Table Extraction using PHP's Simple HTML DOM Parser

I am in the process of extracting HTML data from a local weather channel's website in order to gather closing information for schools, businesses, and churches in my area. However, I am facing an issue as the information is housed within tables that ...

Comparing v-show(true/false) and replaceWith: Exploring the best practice between Vue and jQuery

Currently, I am in the process of learning vue.js and have a question regarding the best approach to implement the following scenario: https://i.sstatic.net/2YBEF.png https://i.sstatic.net/YCEHG.png The main query is whether it is acceptable in HTML to w ...

A guide on retrieving information from a database with PHP and transferring it to Javascript

As I work on creating a website using HTML, CSS, MySQL, and JavaScript, my goal is to allow users to log in and engage in a quiz with 40 questions. Below is the JavaScript code for a countdown timer that includes the "questions" variable. After 40 seconds ...

What are effective ways to eliminate script tags from a webpage?

I have implemented tags on my website that users can use to interact with the site. My goal is to figure out how to make the browser only read text from a specific file I write, without any HTML. This should be restricted to certain sections of my websit ...

Access the configuration of a web browser

I am in the process of creating a website where I need to prompt the user to enable JavaScript. Is there a way for me to include a link to the browser's settings page? Here is an example: <noscript> <div>Please enable JavaScript &l ...

Trouble with Unveiling the Secondary Accordion

I am having issues adding a second accordion next to the existing one. Even though the code is working fine in the tryit editor v3.6 online, it doesn't seem to display correctly for me. I have made sure that I am using the latest versions of all scrip ...

Login block for Episerver

I'm brand new to episerver cms and I'm trying to add a "login block" to the top right corner of my home page where front-end users can log in. I've created a “LoginBlock”, ”LoginBlockController” along with a class called “LoginForm ...

How can you iterate over the input elements that are currently visible within a form using Javascript?

Is there a way to clear the values of all visible input fields in a form using JavaScript? I'm currently struggling with setting text inputs to empty as they come out as undefined. Any suggestions on how to achieve this? ...

JavaScript and AJAX: Dynamically Create URLs

I don't have any experience with web development, so could you please explain in detail? If my questions are unclear, feel free to ask for more information. Imagine I have a webpage with the following URL: www.mycompany.com/category1 This page has ...

The unique format created by tinyMce is not being displayed

I am trying to customize the style format of my tinyMCE, but I am having trouble getting it to show up. Can anyone suggest what might be going wrong? Where should I place the button "Formats" so that I can choose a specific style? tinyMCE.init({ mod ...

Errors in AMP Validator

I have recently started working with next/amp and I am encountering some issues with the amp validator in dev mode. The errors that I am struggling to understand are as follows: An error related to CSS syntax in the 'style amp-custom' tag - show ...

Delete the child element if it is present in an HTML document

removeConnection(event) { let parentElement = document.getElementById('RemoveElement'); let childElement = document.getElementById(event.target.id); parentElement.removeChild(childElement); } Whenever I try to remove the child ...

How to set a custom background image for the Django admin panel

I am struggling to display a background image in the Django admin site. Despite researching multiple solutions, none of them seem to work for me. All I want is for the background to be visible behind the admin site. I have a file named base_site.html. {% ...

utilizing javascript once form elements are dynamically inserted

While dynamically constructing form elements, I encountered an issue with generating unique IDs when the form is submitted. Everything works fine except for the JavaScript function responsible for populating the year in a dropdown selection. The issue ari ...

Calculate the total sum of selected values in a multiple select dropdown using jQuery

Is there a way to calculate the sum of selected items in a multiple selection dropdown menu? For instance, if I select "X12SO" and "X13SO", their values should add up to 30. let total = 0; $("select[name='myselect[]'] option").each(function(){ ...

Steps for creating a new tab and refreshing the address bar with a different URL without having to reload the current page

I'm trying to create a functionality on my page where clicking a button will open a new tab with a modified URL, all without reloading the current page. Below is the code that I'm using when the button is clicked: function changeUrl(){ var pri ...