Prevent scrolling with absolute positioning

Here's a snippet of my HTML pseudocode:

  <div>
    <VideoAnimation />
    <div className="under-animation">
      // a lot of content goes here
    </div>
  </div>

The issue arises from using absolute positioning on the VideoAnimation component, which takes up 100vh in height. This causes it to be taken out of the document flow. To position the under-section right below the animation as if it were relatively positioned, I also set it to absolute position starting from top: 100vh. However, this resulted in an unexpected behavior where I could not scroll through the page properly - only horizontal scrolling worked, while vertical scrolling was disabled on the mousepad. This issue did not occur with relative positioning. Thank you for any insights!

This is how my VideoSection component looks like:

import React, {Component} from 'react';

  render() {
    return (
      <div className="video__container">
        <video autoPlay muted className="myVideo">
          <source
        src="https://res.cloudinary.com/da0fiq118/video/upload/c_scale,h_600/v1538825517/animation.mp4" type="video/mp4" />
        </video>
      </div>
    );
  }
}

export default VideoAnimation;

And here's the SCSS file:

.video {
  &__container {
    bottom: 0;
    left: 0;
    overflow: hidden;
    position: absolute;
    right: 0;
    top: 0;
    z-index: 1;
  }
}

.myVideo {
  display: block;
  height: auto;
  left: auto;
  max-width: none;
  min-height: 100%;
  min-width: 100%;
  right: auto;
  position: absolute;
  top: 0;
  width: auto;
  z-index: 1;
}

@supports (transform: translateX(-50%)) {

  .myVideo {
    left: 50%;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
  }

}

@media screen and (min-aspect-ratio: 16/9){

  .myVideo {
    max-width: 100vw;
    min-width: 100vw;
    width: 100vw;
  }

}

@media screen and (max-aspect-ratio: 16/9){

  .myVideo {
    height: 100vh;
    max-height: 100vh;
    min-height: 100vh;
  }

}

The initial aim was to center the animation at full viewport height in all resolutions by using absolute positioning and adjusting its properties accordingly.

Answer №1

Update:

I believe that using a combination of 100vh and 100vw in the new example code should be sufficient, as there doesn't seem to be a need for the video to remain absolutely positioned.

Check out the updated JSFiddle here

Original post:

It appears that all your content is set to absolute positioning, which is causing the body height issues when trying to scroll.

If it's not necessary for the VideoAnimation element to be absolutely positioned, you can try giving the under-animation div a top margin of 100vh instead of using absolute positioning. This way, the element will still adjust for the video's space while staying within the normal document flow.

Just keep in mind that this solution may not be ideal long-term and could encounter problems if circumstances change. However, without more details, this seems like the simplest approach to take.

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

Dependencies for Grunt tasks

I am facing some issues with a grunt task named taskA that was installed via npm. The task has a dependency on grunt-contrib-stylus, which is specified in the package.json file of taskA and installed successfully. However, when I run grunt default from the ...

Guide to filtering an array within ag-grid when defining a column

After switching from using DataTable to ag-grid, I encountered a challenge. In DataTable, I accessed the first element from the attributes array where typeName='ItemType'. Now, I am looking to achieve the same functionality in ag-grid. Any sugges ...

Encountering issues during React spring installation process

I am struggling with a problem while trying to install react-spring in my react project. Every time I attempt to do so, I encounter a slew of dependency errors and warnings that leave me confused and unsure of how to proceed. Despite searching through th ...

Incorporating Material UI components within an embedded Iframe

Trying to implement Material UI components in an Iframe has been a bit of a challenge for me. There is a DemoFrame component provided by Material UI specifically for this purpose, but the styles don't seem to be inserted correctly into the Iframe. To ...

An issue with jQuery's :not selector and hash symbol syntax

I encountered a syntax error that is quite charming. It appears when attempting to select all anchor tags without an href attribute containing a placeholder URL, such as href="#". Here are the attempts I have made: $("a:not(href='#')"); // cha ...

Tips for creating responsive Math Latex

Check out this link to my website page. Also, take a look at this other link. While using Bootstrap, I've noticed that all content is responsive except for the equations in the first link and the Matrix multiplication example in the second link towar ...

Is it possible to serve CSS using relative paths that go beyond the URL root?

I've encountered a file path issue with my HTML and CSS files. My HTML file is located in: src/test/html/index.html And the corresponding CSS file is in: src/test/css/index.css In the HTML file, the CSS is linked using: <link rel="stylesheet" ...

Is it possible to combine the index page with the login page for a web project, or is it recommended to create a separate login page?

Would it be a violation of any rules if the index page of my web project is used as the login page for users? Do I have to redirect them to a different page? Is this considered best practice? ...

Strange response received from $http GET request on Android device running Crosswalk

I am attempting to retrieve data in JSON format from an API using AngularJS. The process is successful on iOS and desktop browsers, but I'm encountering a strange response when trying it on my Android device. The request code looks like this: $http({ ...

There seems to be a discrepancy where the page content is not appearing within the

I'm currently working on a project where I need to fetch content from an API and display it on a webpage. The fetching process is working well, but I've encountered an issue when trying to view the page source code. It seems that the content retr ...

Tips for successfully sending an array via an XMLHttp Get request

I am currently working on a project where I need to utilize all the values from an array in my GET request. The code snippet below outlines my approach: function executeRequest(){ let data = ['value1', 'value2', 'value3'] ...

Tips on invoking a JSP and Servlet from JavaScript by passing in a parameter

Check out the code below for calling JavaScript functions: <td><input type="button" name="edit" value="Edit" onclick="editRecord(<%=rs.getString(1)%>);" ></td> <td><input type="button" name="delete" value="Delete" onclic ...

When Socket.emit is called, it outputs <span> elements within a well-structured message

Currently working on a small chat application using Node.js, Express.js, and Socket.IO. However, I'm encountering an issue with formatting. Instead of displaying the message content within <span> tags as intended, it is printing out the actual t ...

Utilizing JSX interpolation for translation in React JS with i18next

I am trying to utilize a JSX object within the interpolation object of the i18next translate method. Here is an example code snippet along with its result: import React from "react"; import {useTranslation} from "react-i18next&qu ...

Record collection of elements - JavaScript Angular

I am facing an issue with my page code. The code contains a list of items and I need to extract the values of Test, Application, Success, Error from these items. However, when I try to write this data to a file, it returns [object, Object]. Can someone ple ...

Tips for ensuring that the dynamic view updates correctly when the scope variable is modified

I am currently working on an Angular SPA where a $scope variable plays a crucial role in determining the content of a specific page. When a user clicks on a different link in the menu, parameters are passed through the URL, updating the scope variable. How ...

What is the best way to incorporate data types into a React useReducer reducer function?

I originally had a useReducer function in pure react without TypeScript, but now I want to add types to it. Here is the useReducer reducer function in pure react without types: export const cartReducer = (state, action) => { switch (action.type) { ...

How to center a responsive image in a container using Bootstrap

How can I properly center my banner and place the logo above it? Currently, both elements are not centered as desired. View the live version here: http://codepen.io/anon/pen/waYBxB HTML Code: </head> <body> <!-- LOG ...

What is the best way to transfer a value to v-model using emit?

I'm having trouble passing the selected value from a select field to v-model. Currently, the code only seems to work with a v-text-field. <script> export default { name: 'FormSelect', props: { model ...

methods for transferring JSON data from JavaScript to PHP

I am trying to figure out how to parse JSON data from JavaScript to PHP. Here is my JavaScript code: var Dataconvert; var asetid = new Array(); $("#simpanmodifikasi").click(function(){ var table = $('#tableasal tbody' ...