Any tips on getting my Squarespace Cover page video to resize properly?

I recently implemented a cover page with a looping video background on my Squarespace site. The video used to automatically resize to fit the browser window perfectly, but now it seems to be playing at its full resolution. I don't have much experience with JavaScript or CSS, so any assistance would be greatly valued. Could it be that the code is having trouble identifying the width and height of the "banner" element? You can view the page [here: www.drypowderco.com][1]. Thank you in advance for your help.

<script type="text/javascript">
  $(window).bind("load", function() {
    if( /Android|webOS|iPad|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    } else {
      var banner = $('.sqs-slice-gallery-item > img'),
            height = banner.height(),
                width = banner.width();
      banner.hide();
      var url = "https://zachary-coffin-drsn.squarespace.com/s/Sequence-01_2.mp4";
      $('<video class="bannerVideo" width="' + width + 'px" height="' + height + 'px" autoplay loop><source src="' + url + '" type="video/mp4"></video>').insertAfter(banner);
      adjustBanner($('.bannerVideo'), banner);
      $(window, banner).resize(function() {
        adjustBanner($('.bannerVideo'), banner);
        setTimeout(function() {
          adjustBanner($('.bannerVideo'), banner);
        }, 200);
      });
    }
    function adjustBanner (video, banner) {
      video.css({
        height: banner.css('height'),
        width: banner.css('width'),
        top: banner.css('top'),
        left: banner.css('left'),
        position: 'relative',
         'object-fit': 'cover'
      });
    }
  });
</script>

Answer №1

The banner image on this website is designed to be responsive by default. The 'banner' element mentioned above refers to the img tag that is inserted into the page upon resizing. The actual image used for the banner is hidden from view.

A quick solution is to set both the height and width of the banner to 100% instead of relying on the dimensions of the actual image being displayed.

Here is a suggestion (take note of setting height and width to 100% during initial load and resize events):

<script type="text/javascript">
 $(window).bind("load", function() {
    if( /Android|webOS|iPad|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    } else {
      var banner = $('.sqs-slice-gallery-item > img'),
      banner.hide();
      var url = "https://zachary-coffin-drsn.squarespace.com/s/Sequence-01_2.mp4";
      $('<video class="bannerVideo" width="100%" height="100%" autoplay loop><source src="' + url + '" type="video/mp4"></video>').insertAfter(banner);
      adjustBanner($('.bannerVideo'), banner);
      $(window, banner).resize(function() {
        adjustBanner($('.bannerVideo'), banner);
        setTimeout(function() {
          adjustBanner($('.bannerVideo'), banner);
        }, 200);
      });
    }
    function adjustBanner (video, banner) {
      video.css({
        height: 100%,
        width: 100%,
        top: banner.css('top'),
        left: banner.css('left'),
        position: 'relative',
         'object-fit': 'cover'
      });
    }
  });
</script>

Answer №2

It seems like your video dimensions are dependent on the banner's width and height. It used to function this way, although it's unclear why. One potential solution is to utilize...

$(window).width();
$(window).height();

For instance:

var banner = $('.sqs-slice-gallery-item > img'),
        height = $(window).height(),
            width = $(window).width();

In addition:

video.css({
    height: $(window).height(),
    width: $(window).width()
    top: banner.css('top'),
    left: banner.css('left'),
    position: 'relative',
     'object-fit': 'cover'
  });

Another option is to set fixed dimensions for your banner, enabling the video to adapt accordingly.

Please note that I have not verified if this method will be effective.

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

I am looking to view all products that belong to the category with the ID specified in the request, and have red-colored stocks

Within my database, I have defined three mongoose models: Product, Category, and Stock. The Product model contains two arrays - categories and stocks, each including respective category and stock ids. My goal is to retrieve all products where the category_ ...

Attempting to retrieve access token for Paylocity Web API in Node.js, encountering the issue of receiving an "invalid_client" error message

I've been attempting to retrieve the access token for the paylocity API. I can successfully obtain it through postman using the client id and client secret, but when I try to do so with Node.js, I receive the message {"error":"invalid_client"}. Below ...

What are some ways in which I can utilize the Ember Handlebars helper?

Similar Question: Using logical operators in a Handlebars.js {{#if}} statement Below is the code snippet provided: {{#each dataArray}} <li>{{#isTrue idVal1 idVal2}} display some text1 {{else}} display some text2 {{/isTrue}} & ...

When attempting to retrieve data from an API in Angular 8, I encountered difficulties in dynamically creating a formArray within a formArray

I am struggling to dynamically create form controls based on the data received, specifically for fields like task and template name. Your assistance is greatly appreciated. { "items": [ { "templatename": "Defult" ...

Stop a hacker from obtaining the usernames from a system

Our forgot password page has been identified with a security issue that needs attention: ISS-0003938 Web Inspect Open Medium Suspicious Files Found in Recursive Directory ****** Remove any unnecessary pages from the web server If any files are nec ...

Activating a certain class to prompt a drop-down action

My PHP code is displaying data from my database, but there's a bug where both dropdown menus appear when I click the gear icon. I want only one dropdown to appear when clicking the gear of a specific project. Can you help me fix this issue? It's ...

Is it possible for me to create personalized color definitions that I can seamlessly use across CSS, JavaScript, and HTML files?

I'm currently using a shade of blue throughout my app, and I find myself repeatedly copying and pasting the color code in my CSS styles. Is there a way to create a constant for this specific color that can be shared across my CSS, HTML, and JavaScript ...

An issue occurred in the nextTick function: "RangeError: The maximum call stack size has been surpassed" within the ViewTree component

Encountering an issue with selecting children in a tree view, here is the code snippet for my treeview: <v-treeview v-model="selection" :items="questionnaires" :selection-type="selectionType" selectable ...

Render doesn't wait for the componentWillMount lifecycle method

I'm currently working on implementing a redirection to the home page for logged-in users. I'm using ping to fetch login information, setting a state based on the response, and then checking that state in the render method for redirection. However ...

Utilizing the ng-if directive to choose the second element within an iteration of an ng-repeat loop

I am currently working on a project where I need to organize and group content by day. While the grouping function is working fine, I am facing an issue with treating the first two items in the loop differently from the rest. I have experimented with using ...

Tips for managing a stored data reservoir with react-query

I am looking to develop a unique custom hook that can effectively manage a cache and fetch only new items. Here is the expected behavior: Upon initial request for [1, 2, 3, 4, 5], it should fetch all [1, 2, 3, 4, 5] as the cache is empty. If a request is ...

Create a loop to iterate through dates within a specified range using the Fetch API

When I need to get the exchange rate from the bank for a specific interval specified in the input, I follow these steps. The interval is defined as [startdate; enddate]. However, in order to make a successful request to the bank, the selected dates must be ...

Stylesheet failing to respond to CSS Media queries

I have looked at other questions with similar issues and it appears that what's missing in their code is: <meta name="viewport" content="width=device-width, initial-scale=1"> However, I already have this code implemented but still facing probl ...

What is the best way to initiate a background process upon the startup of a Windows WinRT/C# device or application?

What is the ideal way to initiate a background task that utilizes IBackgroundTask in a universal app designed for windows/windows phone? In my development process with cordova, I am crafting an application for ios, android, wp8 and windows. Each platform ...

Is there a way for me to retrieve the information sent in a jQuery Ajax request?

I'm struggling to understand how to retrieve a value previously submitted to a PHP file using AJAX and jQuery. I'm still in the early stages of learning jQuery, so some concepts are challenging for me. Below is my jQuery code: $('#button2& ...

Occasionally, the Axios ajax request may return HTML as a response

While working with Vue.js 2, I encountered an issue with my ajax call using axios. Everything was working fine until I navigated to another page and returned to the page with the ajax call, where it suddenly started returning html instead of json objects. ...

Optimal banner image dimensions for responsive mobile display on various devices

What is the best way to ensure a banner image looks good on small and medium mobile devices, as well as tablets? ...

Is jQuery AJAX returning improperly formatted JSON when using the jsonp type?

$('#rn_s').keyup(function() { var rn = $('#rn_s').val(); if(rn.length == 9) { $.ajax({ url: 'http://routingnumbers.info/api/data.json?rn=' + rn, type: 'GET', dataT ...

Utilizing SEO and incorporating special characters like !# in a website's URL

I came across an interesting concept about designing a website that utilizes AJAX to load each page section without compromising SEO. It involved incorporating !# in the URL, similar to the approach adopted by Twitter. However, I've been unable to loc ...

Make the Angular spinner's position fixed at the top

HTML <div class="margin-top-10"> <span us-spinner="{left: '91.6%',top:'74.2%',length: 5,width: 2,radius:4}" spinner-key="spinner-1"></span> <button class="btn btn-green" ng-click="">Send</butt ...