Utilize the browser/page scroll bar to navigate through the fixed-position div's content

I have several div elements with the CSS property position:fixed positioned all over the page. One of these divs contains longer content than the others.

My goal is to enable scrolling within that specific box using the main browser/page scroll-bar, as opposed to the normal overflow:auto method demonstrated in this example: like this. The exact scenario can be viewed at

Is there any plugin available that can help achieve this functionality?

Answer №1

If you are not familiar with HTML syntax:

<body>
    <section id="mainContent"></section>
    <header></header>
    <section id="leftPanel"></section>
    <section id="rightPanel"></section>
</body>
#mainContent {
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    min-height: 100%;
    width: 100%;
    padding: 90px 45px 0px 105px;
    background-clip: content-box;
    background-color: #FFFFFF;
}

body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background-image: url(page_bg.jpg);
    background-attachment: fixed;
}
header, #leftPanel, #rightPanel {
    position: fixed;
}
header {
    top: 0;
    width: 100%;
    height: 90px;
    background-image: url(page_bg.jpg);
    background-attachment: fixed;
}
#leftPanel {
    left: 0;
    top: 0;
    height: 100%;
    width: 105px;
    padding: 90px 0 0 0;
}
#rightPanel {
    right: 0;
    top: 0;
    height: 100%;
    width: 45px;
    padding: 90px 0 0 0;
}

By utilizing this structure, the contents of #mainContent will be contained within the borders of the surrounding elements, causing overflow to display a scrollbar on the body as specified. View example on JSFiddle.

Answer №2

Perhaps this idea has potential. I have created a jsFiddle that demonstrates the concept. It may not be flawless, but there is room for further development... Please note that this code snippet is best suited for modern browsers, although it can be adapted for older versions of Internet Explorer. Below is the key code:

JavaScript:

window.onload = function () {
    var content = document.getElementById('contentwrapper'),
        dimdiv = document.getElementById('scrollingheight'),
        wrapHeight = document.getElementById('fixed').offsetHeight,
        scroller = function () {
            content.style.top = -(document.documentElement.scrollTop || document.body.scrollTop) + 5 + 'px';
            return;
        };
    dimdiv.style.minHeight = (content.scrollHeight - wrapHeight + 2 * 5) + 'px';
    window.addEventListener('scroll', scroller, false);
    return; 
}

CSS:

#fixed {
    position: fixed;
    min-width: 300px;
    min-height: 200px;
    max-height: 200px;
    background: #fff;
    left: 150px;
    top: 200px;
    overflow-y: hidden;
    border: 1px solid #000;
}
#contentwrapper {
    max-width: 290px;
    position: absolute;
    top: 5px;
    left: 5px;
}
#scrollingheight {
    position: absolute;
    top: 100%;
    visibility: hidden;
    min-width: 1px;
}

HTML:

<div id="scrollingheight"></div>
<div id="fixed">
    <div id="contentwrapper">
        content
    </div>
</div>

It's important to note that all content within the body, except for #scrollingheight, needs to be fixed. The constant value of 5 corresponds to the top property of #contentwrapper.

Answer №3

From my understanding, it seems impossible to accomplish that task.
Unless you resort to some advanced JavaScript techniques.
Why? Well, because adjusting the default scrollbar height of a browser (making it smaller) to accommodate content in a different part of the html, body (document) is not feasible.
I recommend creating a custom scrollbar instead, measuring the height of your sleek overflow hidden section, and factoring it into the scrolling calculation.

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

Place an image at the center with a height set to 100% within a div that has a fixed height and

Apologies for asking about this topic again, but I have been unable to find a solution where the image fills 100% of the height. If you'd like to see the issue in action, here's a link to the jsfiddle: http://jsfiddle.net/BBQvd/3/ I'm just ...

Indeed, verifying parent.parent access

Currently, I am utilizing the yup module to validate my form. My objective is to access the parent in order to test the value. Below is my schema: enabled: yup.boolean(), contactDetail: yup.object().shape({ phoneNumber1: yup.string().nullable(), pho ...

I am interested in dynamically changing the texture/material of a .obj file during runtime with the click of a button using three.js

Whenever I try to load my model and change its texture, the model doesn't load and nothing appears on the screen. I am new to three.js/webgl languages and javascript. Can someone please provide me with the correct information to move forward? Below is ...

Finding specific data in sessionStorage using an ID or key

I have stored data in sessionStorage and this is an example of how I save the data: $.ajax({ type: 'POST', url: 'Components/Functions.cfc?method='+cfMethod, data: formData, dataType: 'json' }).done(function(ob ...

What happens if I define both the left and right properties for spans?

This is a class for span with the CSS properties position:absolute; top:0px; left:0px; right:0px; .textStyle1 { font-size:24px; font-family:'Arial'; position:absolute; top:0px; left:0px; right:0px; } #div1 { position:absolute; lef ...

"Combining the CakePHP media plugin with the dynamic functionality of the jQuery File

MY SITUATION: In the midst of my Cakephp project, I've been utilizing David Persson's media plugin alongside the jQuery Fileuploader plugin based on this tutorial, which has proven to be quite effective. The complication arises in that I requir ...

Utilizing the Google Maps API to display markers within a custom-drawn polygon

My goal is to display markers inside a drawn polygon on a Google Map. For example, when a user draws a polygon on the map, I want to show markers that fall within that polygon. Specifically, I am referring to drawing polygons. I have also attached a screen ...

JavaScript's getDate() function is failing to properly adjust the date when performing addition and subtraction operations

I have been facing an issue with a JavaScript function that is supposed to adjust the date when a button is clicked. The function is intended to utilize the getDate() function to subtract 7 days from the current date value displayed in the textbox. However ...

Merge two primary loops within a single node.js process

Looking for a way to receive system notifications and pass them through http to the client. Currently using node.js to handle both services in one process, but encountering an issue. The notification listener has its own main loop that listens to system e ...

Having trouble sending POST requests in Express?

I developed an API and all the routes were working perfectly until now. However, when I attempted to send a POST request to the "/scammer" route, I encountered the following error message: Error: write EPROTO 1979668328:error:100000f7:SSL routines:OPENSSL_ ...

The data visualization tool Highchart is struggling to load

As I try to integrate highcharts into my website, I encounter an unexpected error stating TypeError: $(...).highcharts is not a function. Below is the code snippet in question: @scripts = {<script src="@routes.Assets.at("javascripts/tracknplan.js")" ty ...

Tips for updating the appearance of navigation bar links by changing text and background colors upon hover:

I need assistance changing the text color of my navigation bar links when hovering over them. The background is currently changing, but I want both the background and text to change simultaneously when hovered over. It seems to be working for the sub links ...

How can you use ng-click to disable a div in AngularJS?

I'm looking to dynamically disable a div in AngularJS based on a certain condition. I know I can achieve this by adjusting the CSS (such as reducing contrast and color) but the div also has an ng-click property that I want to prevent from being trigge ...

Floating an Image to the Right of Bootstrap Tabs

In my Twitter Bootstrap nav-tabs, I have an image that follows all of my tabs, and I want it to float right. I've experimented with changing the float, text-align, and other properties, including using the pull-right class from another related SO ques ...

Tips for transforming a few Nuxt snippets into Vue components

What is the best approach to transform this Nuxt script into a Vue-compatible one? <script> export default { components: { FeaturedProduct }, async asyncData({ axios }) { try { let response = await axios.get( 'http:// ...

Creating a flexible layout using Flexbox

Currently, I have successfully coded a layout using Grid, but now I am looking to achieve the same layout using FlexBox due to compatibility issues with IE-11. Unfortunately, IE-11 does not support Grid properly. Let's simplify things and focus only ...

The words streaked across the page like shooting stars, leaving

On my website, I'm facing an issue with text overflowing off the page when the podcast listing page is viewed on a small screen: https://i.sstatic.net/ZAR6Z.png I stumbled upon this helpful Stack Overflow answer that suggests using a specific CSS cl ...

Pagination not displaying results beyond the initial page

Having an issue with my current pagination setup. The first page displays the correct number of records and page links, but when I navigate to a different page, no records or page links show up. If anyone can spot where the problem might be occurring, it ...

Conceal player controls for HTML videos on iOS devices

How can I hide the video player controls in Windows and Android, they are hidden but still visible on iOS. I have tried different methods but can't seem to hide them. Here is what it looks like on iOS: https://i.sstatic.net/Uwrg3.png Here is my code ...

How to use Laravel to show a graph sourced from a separate database connection

Is it possible to create a pie or doughnut chart in Laravel using data from a separate database connection ('mysql2' in the .env file)? I have successfully generated charts from the main database, but this time I didn't migrate the second da ...