Achieving unique proportions with HTML5 video resizing

On my page, I plan to showcase a video specifically for desktop browsers. I have devised some code to determine whether the video is in landscape or portrait orientation. The challenge lies in deciding what to do based on this orientation: If the video is in portrait mode, it should be displayed accordingly (playing where the balloons are positioned). However, if the video is in landscape mode, I simply want it to fill the space minus a margin along with the black background.

https://i.sstatic.net/RsEFR.jpg

Below is the HTML snippet:

<div id="vidmodal" class="video-wrapper" ng-show="vm.showVideo">
    <img src="public/img/cancel-music.svg" alt="" id="closeX">
    <video src="{{vm.event.videoUrl}}" id="vid" loop autoplay muted poster="{{vm.event.imageUrl}}"></video>
</div>

JS Function:

function clickPlay() {
      vm.hasVideo  = false; //hide the text-and-play-button div
      vm.showVideo = true; //show the video which is default hidden (false)

      var bgVideo = document.getElementById("vid");
      if (bgVideo.videoWidth > bgVideo.videoHeight){
          console.log('landscape vid');
          $('.rsvpbox').css('background-color', 'RGBA(255,255,255,0.6)');
      } else if (bgVideo.videoWidth < bgVideo.videoHeight){
          console.log('portrait vid');
          $('.rsvpbox').css('background-color', 'RGBA(255,255,255,0.6)');
          $('.rsvpbox').css('left', '80px');
          $('#vid').css('max-width', '320px !important');
      } else {
          $('.rsvpbox').css('background-color', 'RGBA(255,255,255,0.6)');
      }
}

CSS Styling:

@media screen and (min-width: 1024px)
{
  #vidmodal
  {
    position: absolute;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: black;
    z-index: 9999999;
  }
  #closeX
  {
    position: absolute;
    right: 0;
    z-index: 99999999;
  }
  #closeX:hover
  {
    cursor: hand;
    cursor: pointer;
  }
  video
  {
    z-index: 9999999;
    position: absolute;
    left: 0;
  }
  .btnBox 
  {
    padding-left: 15px;
    padding-right: 15px;
    width: 550px !important;
    position: relative;
    right: 70px;
  }
}

Answer №1

According to @Salketer's feedback, the key elements that were absent were max-width and max-height attributes.

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

What is the process of including a pre-existing product as nested attributes in Rails invoices?

I've been researching nested attributes in Rails, and I came across a gem called cocoon that seems to meet my needs for distributing forms with nested attributes. It provides all the necessary implementation so far. However, I want to explore adding e ...

Personalizing text in HTML using JavaScript results

I have a modal dialog box function that pops up when a user clicks a button, triggered by a javascript/jquery script. The text displayed in the dialog is set up within an HTML div element that references the script function. My query is how to personalize ...

Elements powered by jQuery failing to load upon dynamic webpage(s) loading via ajax

Dynamic loading of jQuery elements, such as Ibuttons, seems to be causing issues when implemented with an ajax dynamic content loader. The entirety of my website is rendered through Ajax just like this: <html> <header> {jQuery} </header> ...

The browser is preventing files from being accessed through Express because they do not have the text/html MIME type

Currently, I am attempting to set up a nodejs express web server with a static frontend. In order to handle the GET requests made to /, I have implemented myServer.use(express.static("public"));. Within the public folder are HTML, JavaScript, CSS, and im ...

Place the menu within the image, positioned at the bottom

Could someone help me with placing a menu at the bottom of an image using HTML, CSS and Bootstrap 4? I have limited CSS knowledge and need assistance. Currently, my navbar is located below the image but not within it like this: I am looking to achieve so ...

"Looking to programmatically close a modal in JavaScript that was opened using the 'data-target' attribute? Here's how you can

I have a modal template embedded in the same HTML file as my controller. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modalDeleteItem">Delete selected item</button> < ...

What could be causing one of my images to not appear on my Gatsby page?

Hey there, I could use some help with this issue: Recently, I created a website using Gatsby.js and deployed it to my web server (which is running NGINX on Ubuntu 20.04). The site uses Gatsby Image for querying and displaying images, and everything seems t ...

AngularJS $resource sends the id as a query parameter rather than including it in the URL

I'm trying to retrieve data from a rest API by using the product id as part of the URL, rather than as a query parameter. Here is the factory code: .factory('Products', ['$resource', function($resource) { return $reso ...

Validating (Update database with correct email and token)

Authentication (Update database if email and token are accurate) Even when the code is incorrect, it displays "Great Success", but the status does not update in my database. However, if I input the correct code, it shows "Great Success" and updates the s ...

Retrieving ViewBag Data following a successful $.ajax post in C# .NET Razor

When I use ajax to post data, it successfully goes through. However, when I try to retrieve the posted data from ViewBag on the controller side, I encounter an issue. Here's the Ajax Code: $.ajax({ type: "POST", url: '../Home/ ...

What is the best way to increase the space between table columns in CSS?

I'm struggling to increase the space between the columns in a simple table with two columns. The column-gap property doesn't seem to be working for me. Any suggestions on how I can achieve this? JSFiddle #t td { -webkit-column-g ...

Avoid using the FONT tag with the execCommand function

Is there a way to hide the next element using execCommand configuration? Font Tag <font color="xxxxxxx"></font> I am facing an issue while creating a simple editor for a project. I am struggling with CSS formatting and the font tag is not he ...

Troubleshooting: CSS property "background-color" malfunctioning

Recently, I've been attempting to implement CSS variables into a simple code but have encountered issues. Despite double-checking the information on how to properly use variables, I can't seem to pinpoint my mistake. Could it be that I am doing s ...

Ways to increase the spacing between content boxes using Bootstrap

I currently have a row of three Bootstrap boxes structured like this: <div class="row"> <div class="col-lg-4 pathBoxMain"> <h2>Content</h2> </div> <div class="col-lg-4 pathBoxMain"> <h2>Content</h2> </di ...

How can we efficiently trigger a function that sends an axios request by leveraging data from a v-for loop?

Currently, I am developing an e-commerce platform using Rails and VueJS. In order to display the orders of a specific user, I have created a component file. Within this component, I am utilizing a v-for loop to iterate over and showcase all the information ...

What is the best way to compare two strings without considering their capitalization?

Here is the issue I am facing: mytext = jQuery('#usp-title').val(); Next, I check if the text matches another element's content: if(jQuery("#datafetch h2 a").text() == mytext) { However, titles can vary in capitalization such as Space Mi ...

Displaying a dynamic splash screen during the resource-loading process on an Android application

I would like to implement an animated image (currently using a set of PNGs) as a splash screen while my resources are loading. I have successfully displayed the splash screen using this method. However, the issue I am facing is that the splash screen appe ...

What is the purpose of specifying http://localhost:3000 when accessing API routes in Next.js?

I created an API route within the pages directory of my NextJS project. It is functioning properly as I am able to retrieve data by directly accessing the URL like http://localhost:3000/api/tv/popular. My goal is to fetch this data using getStaticProps and ...

The comparison between createElement() and AJAX response

Currently, my website has a login form that updates the page with user data through AJAX after successful login. To maintain semantic integrity, I use JavaScript to remove the login form from the page once the user is logged in. However, when the user lo ...

Enhance the overall appearance of select elements across all components using Material UI's

I'm attempting to change the border color of my outlined select elements using the code below, but it's not working as expected. It seems that the border style is being inherited from the fieldset element. I've experimented with using MuiOut ...