Fixing the issue with CSS scrollbar swapping

I'm currently working on a template and facing a challenge that I can't quite comprehend. More specifically, I understand why it's happening, but I'm struggling to implement a cross-browser solution.

The issue revolves around a fixed block where the initial scroll is not available, but an empty scroll bar is displayed from the body to prevent the image from jumping into the carousel. Upon clicking, the scrollbar is supposed to be replaced and the scrollbar of the .content-wrapper block should be displayed.

However, this functionality seems to only work in Chrome, as in other browsers the scrollbar of .content-wrapper disappears under the carousel...

Is there a way to achieve a cross-browser solution for this problem?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>Title</title>

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">

    <style>
        html,
        body {
            height: 100%;
            min-height: 100%;
            padding: 0;
            margin: 0;
        }

        body {
            overflow-y: scroll;
        }

        body.scroll {
            overflow-y: hidden;
        }

        .content-wrapper {
            height: 100%;
            min-height: 100%;
            width: 100%;
            position: fixed;
        }

        body.scroll .content-wrapper {
            overflow-y: scroll;
        }

        .carousel-wrapper {
            position: fixed;
            width: 100%;
            height: 100%;
            min-height: 100%;
            z-index: 1;
            background-color: black;
        }

        .content {
            position: relative;
            background-color: rgba(241, 156, 187, 0.5);
        }

    </style>
</head>
<body onclick="this.setAttribute('class', 'scroll')">
<div class="content-wrapper">
    <div class="carousel-wrapper">
        <div class="cover"></div>
        <div id="carouselSlides" class="carousel slide carousel-fade align-self-sm-center align-self-md-start"
             data-ride="carousel" data-interval="7500"
             data-pause="false">
            <div class="carousel-inner">
                <div class="carousel-item active"><img
                        src="https://store-images.s-microsoft.com/image/apps.18496.14408192455588579.aafb3426-654c-4eb2-b7f4-43639bdd3d75.2c522ca4-9686-4ee2-a4ac-cdbfaf92c618?mode=scale&q=90&h=1080&w=1920"
                        class="d-block min-vw-100" alt="">
                </div>
                <div class="carousel-item"><img
                        src="https://149351115.v2.pressablecdn.com/wp-content/uploads/2018/12/Stack-Gives-Back-2018-.png"
                        class="d-block min-vw-100" alt="">
                </div>
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <div class="content" style="height: 10000px">
            content
        </div>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
        integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</body>
</html>

Answer №1

My latest project yielded the desired outcome, with just a slight hiccup in IE...

Has anyone else encountered this issue and found a workaround?

Strange scrolling behavior in Internet Explorer causing a fixed block to leave a 1px gap

https://i.sstatic.net/rlTzT.png

Here are some adjustments to the layout:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>Title</title>

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet">

    <style>
        html,
        body {
            height: 100%;
            min-height: 100%;
            padding: 0;
            margin: 0;
        }

        body {
            position: fixed;
            overflow-y: scroll;
            width: 100%;
        }

        body.scroll {
            position: relative;
        }

        .carousel-wrapper {
            position: fixed;
            z-index: 1;
        }
    </style>
</head>

<body>
<div class="carousel-wrapper">
    <div class="cover"></div>
    <div id="carouselSlides" class="carousel slide carousel-fade align-self-sm-center align-self-md-start"
         data-ride="carousel" data-interval="7500"
         data-pause="false">
        <div class="carousel-inner">
            <div class="carousel-item active"><img
                    src="https://store-images.s-microsoft.com/image/apps.18496.14408192455588579.aafb3426-654c-4eb2-b7f4-43639bdd3d75.2c522ca4-9686-4ee2-a4ac-cdbfaf92c618?mode=scale&q=90&h=1080&w=1920"
                    class="d-block min-vw-100" alt="">
            </div>
            <div class="carousel-item"><img
                    src="https://149351115.v2.pressablecdn.com/wp-content/uploads/2018/12/Stack-Gives-Back-2018-.png"
                    class="d-block min-vw-100" alt="">
            </div>
        </div>
    </div>
</div>
<div class="content-wrapper container-fluid">
    <div class="content" style="height: 10000px">
        content
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.5.1.min.js"
        integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script>
    $('body').on('click', function () {
        $(this).toggleClass('scroll');
    });
</script>
</body>
</html>

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 best method for starting a string using the symbol '~'?

Hello everyone! I have a task that requires me to add a special feature. The user needs to enter something in a field, and if it starts with the tilde (~), all subsequent entries should be enclosed in a frame within the same field or displayed in a list ...

In order to ensure JavaScript can be universally applied to all images, it needs to be made more generic

I have developed JavaScript functions to enable zoom in and zoom out functionality for an image through pinching gestures. Now, I aim to refactor the code below so that I can include it in a shared JavaScript file. var scale = 1; var newScale; ...

identify when the React component has reached the bottom of the element by reading the

Is there a way to access the scroll handler's event without being able to access offsetTop, scrollTop, etc? class App extends React.Component { handleScroll = e => { console.log(e.target.scrollTop); }; componentDidMo ...

Customize Angular Material's Mat-Dialog background blur/darkening effect

Greetings, dear community members, I am currently utilizing angular along with angular material in my projects. By default, when a material dialog is opened, it slightly darkens the background. However, I am interested in having a blurred background inst ...

unique map customized in a separate browser window

Attempting to complete the code provided here but encountering issues as a novice in java-scripting. It seems like the map is not loading correctly. A new tab and text are generated when DIV is created. Seeking assistance on how to open a custom map in a ...

IE 11 does not support the use of absolute positioning with a height of 100%, however, this functionality works perfectly on Microsoft Edge

It appears that in IE 11, my absolutely positioned element is not displaying within another element with a height:100%. Strangely, it only works if I assign a fixed height to the element (even though its parent has a fixed height). Here is the HTML code: ...

BASH-SHELL SCRIPT: Display a specific portion of content from a file

Recently, I stumbled upon a text file containing a snippet of HTML code: >>nano wynik.txt which includes the following text: 1743: < a href="/currencies/lisk/#markets" class="price" data-usd="24.6933" data-btc= "0.00146882" My goal is to extr ...

Using javascript, hide or show a div without using jquery or the display:none property

I am looking for a way to show/hide a div up and down, but I have some requirements: I cannot use jQuery: toggle(), slideToggle(), fade, animate, etc. all use display: none, and I need the div to still occupy space in the DOM (I will be processing things ...

What is the best way to maintain parameters in PHP form code?

I am facing an issue with a script that needs to run with a specific parameter (for example, details.php?studentid=10325). The script contains a form with the following code snippet to send form data back to the current script. However, for some reason, t ...

CSS animations are not running as expected

Currently, I've been experimenting with a basic CSS animation. The objective is to make the application logo move 200px to the right and then smoothly return to its original position. Below is the code snippet I've used for these animations: /* ...

Node.js error: HTML audio file returns 404 on server but plays fine when accessed directly as an HTML file

I'm facing an issue with an HTML page that contains an autoplay tag for a song (the file is in mp3 format). When I open the page as a local file on my Mac, the song plays fine. However, when I try to run it using a node.js file with socket.io, the son ...

The Bootstrap 5 Navbar dropdown is not as responsive as the dropdown showcased in the official documentation

I tried utilizing Bootstrap 5 to implement a dropdown functionality, but unfortunately, the dropdown on my website isn't behaving as expected. Unlike the dropdown in the official Bootstrap documentation, my dropdown remains open at all times even when ...

Emphasize multiple anchor points

I am looking to highlight two sections of a page simultaneously. Here is what I currently have: <li class="langLI" style="list-style-type:none"><a href="/non-discrimination-and-language-assistance##French">| French Creole</a></li> ...

"Is it possible to keep an eye on two different events and take action once they both

I have a menu with different submenus for each list item, all utilizing the same background tag. Currently, when one submenu is open and I hover over another list item, the previous submenus hide and the new one opens. What I want is for the content to cha ...

Manipulate the value of an HTML element's style parameter with jQuery

How do I change an element's style property using jQuery? This is the HTML code I am working with: <div id="template" style="width:200px; height:200px; border:none;">blabla...</div> I attempted to do this: $('#template').attr ...

A guide to filling an irregular shape (such as a star) based on a percentage using CSS in a React project

I am currently working on developing a React component that showcases a rating percentage using a star icon with two different shades. For example, if the input rating is 79%, I want to display a star with 79% of it in gold color and the remaining 21% in ...

CSS - reduce the size of an element rather than the entire page

Looking to create a page with 2 divs where the first div automatically shrinks and adds scrollbars when the browser window height is decreased, while the second div maintains its height. Wondering if this can be achieved using only CSS. <div class="s ...

What is the best method for submitting an ajax form post when it is dynamically loaded within a bootstrap modal window?

Need some help with a Bootstrap modal form that is not submitting via AJAX as intended. When the form is submitted, the entire page reloads instead of having the data posted in the background. How can I fix this while keeping the page state? Below is the c ...

Guide on adding CSS3 ribbons to elements on both sides

I recently came across a tutorial that teaches how to create a CSS ribbon. However, after following the tutorial, I found that the ribbon only appears on one side of the element. This has left me wondering if it's possible to have the ribbon display o ...

Prevent vertical scrolling only on mobile devices while allowing horizontal scrolling

Currently, I am working on a web page that utilizes a horizontal layout. However, when viewing the page on mobile devices, I want to restrict scrolling to only the horizontal direction, preventing users from being able to scroll up or down. As it stands n ...