Create a specific part of a webpage that can be scrolled through

In a unique way, I have designed a page where the only way to navigate is by simply clicking.

To achieve this, I have implemented the following custom CSS:

body{
    overflow:hidden;
}

However, I have encountered a problem where I am unable to scroll to a specific section of my page if the link is not visible. This requires that a certain part of the page should be scrollable.

In the sample fiddle provided, I am facing this issue with "Div3": Check it out here

Can anyone suggest how to make only the section displaying "Div3" scrollable and not affect the rest of the page?

UPDATE:

Applying overflow-y: scroll; to "Div3" is not an option as it affects the entire width of the page. This causes the contents of "Div3" to shift, which is not the desired outcome.

Answer №1

To enable scrolling for #div3, you can enclose its content within an additional container like this:

<div id="div3">
    <div class="content">
        <h3>Div 3</h3>
        <a href="#div4">Next</a>
        <a href="#div2">Prev</a>
    </div>
</div>

Adjust your CSS to ensure that the container can scroll:

#div3 {
    overflow-y: scroll;
}

Check out the modified fiddle to see this method in action.

Edit

If your goal is to determine if #div3 is the sole element within the viewport and occupies the entire viewport, you can use the following jQuery code:

var $div3 = $('#div3'),
    div3Top = Math.round($div3.offset().top),
    div3Bottom = $div3.height() + div3Top,
    $window = $(window),
    $body = $('body');

$(window).on('scroll', function() {

    console.log($window.scrollTop());
    console.log(div3Top);    
    console.log(div3Bottom);

    if (($window.scrollTop() >= div3Top) && ($window.scrollTop() + $window.height()) < div3Bottom + 5) {
        $body.css('overflow', 'scroll');
    } else {
        $body.css('overflow', 'hidden');
    }
});

While not flawless, this code illustrates the concept effectively.

Find the updated fiddle here.

Answer №2

This may not be the most elegant solution but it gets the job done:

$(window).scroll(function() {
    $('#message').text("Current scroll position: " + $(this).scrollTop());//added to see the scroll position
     var pixels_to_top = $(this).scrollTop();
        var your_value_min = 810;
            var your_value_max = 857;
        if (pixels_to_top > your_value_min && pixels_to_top<your_value_max){
             $("body").css("overflow","auto");
           }
    else{
     $("body").css("overflow","hidden");
    }
});

http://jsfiddle.net/Loy6z2kt/18/

Remember to adjust the min and max values to your specific requirements.

Answer №3

In response to your recent comments on the original post, I wanted to mention the effect you are looking for on the specified website is known as parallax scrolling. For examples, you can visit Parallax examples or follow a tutorial like the one provided here: Parallax scrolling tutorial. Please note, the advanced tutorial mentioned in the latter link may require payment.

If parallax scrolling is not what you are looking for, feel free to update your question accordingly, similar to how you previously modified the overflow-y: scroll property.

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 sets npm node-sass apart from npm sass?

Recently, I discovered that the recommended approach is to utilize @use rather than @import in sass. However, it appears that using npm sass instead of npm node-sass is necessary for this. Can you clarify the distinction between these two? Also, why do @ ...

An issue of an infinite loop arises when utilizing the updated() lifecycle hook in VueJS

I am working on a VueJS application where I need to fetch a list of articles in one of my components. The logic is such that if the user is logged in, a specific request is made, and if not, another request is executed. Below is the snippet of code: <s ...

The alignment of buttons is not defined for ASP buttons and Bootstrap dropdowns

I'm having an issue with the placement of my ASP button and button dropdown list. The dropdown always appears below the other buttons, but I want it to be in the same row as the other buttons. Below is a screenshot showing the current layout of the b ...

Identify whether the Vue model change was initiated by user input or programmatically

I am facing an issue with Vue's reactivity when using a custom component in Quasar 2. Let me explain the scenario: The custom component includes two radio buttons and a select dropdown. Whenever the user changes one of the radio selections, the selec ...

The Hamburger Menu Opens Smoothly But Refuses to Shut Down

Below is the HTML code for my website. I have managed to open the hamburger menu with the code, but I am facing an issue where it won't close. I have checked the HTML structuring using a validator and found no errors. Additionally, I have reviewed my ...

The Facebook page plugin fails to function properly following an AJAX page load

Having an issue displaying a Facebook page on my website. I've implemented the new page plugin available here. The problem arises when the plugin only loads properly upon initial page load. If I navigate to another page and return, the plugin ceases ...

Using dual ngFor in Angular 4: A step-by-step guide

I am encountering an issue in my Angular 4 project where I receive two different arrays in response to a server request, and I want to utilize both of them in the template. Here is my controller code: this.contractService.getOwnerContract() .subscribe( ...

What method does the browser use to select the srcset image for loading when no sizes attribute is included?

My website features an image that is displayed in various sizes depending on the browser dimensions: Since the website is responsive, the image's width can range from 200 to over 1000 pixels, depending on the size of the browser window. We aim to sho ...

Strategies for managing large numbers within WebGL GLSL shader programs

What is the best approach to handle large numbers like the one provided in GLSL? I have a shader that requires Date.now() as a uniform, which is defined as: The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 ...

Could not locate the express.js file

Currently in the process of learning express/node.js, but struggling to locate the page at localhost:3000/info You can view screenshots of my code below ...

Transferring the value of my PHP variable to a JavaScript file

Hello everyone, <script src="../../record/recordmp3.js?id=<?php echo $_GET['id'];?>&&test_no=<?php echo $_GET['test_no'];?>"></script> <script type="text/javascript" data-my_var_1="some_val_1" data-m ...

The Font Awesome icon is not displaying on top of the Materialize CSS progress/determinate bar

I am struggling to display a Font Awesome icon on top of a Materialize CSS progress/determinate div. Unfortunately, the icon is not fully visible and part of it gets clipped or hidden. Despite trying various solutions, I have not been successful. .progres ...

Adjust the CSS to ensure that all elements have the height of the tallest element in the set

Can anyone help me solve a design issue I'm facing? I have a div with three floating buttons, but one of the buttons is taller than the others due to more content. I'm looking for a way to ensure that all buttons are the same height as the talle ...

What is the method for retrieving an array or object that contains a collection of files designated for uploading within the jQuery file upload plugin?

Currently, I have successfully integrated a form into my Rails site and set up the jQuery file upload plugin. The upload form functions properly with the ability to select multiple files and utilize all ajax upload features. However, a challenge I am faci ...

Ensuring the Selection with jQuery

I've successfully implemented jQuery validation on a text field, but when I try to apply it to a radio button, it doesn't seem to work. I'm not sure what I'm doing wrong. Here is my HTML and jQuery code: <input type="text" placehol ...

The div above the footer seems to be interfering with the styling of the footer. Is there a solution to

I am currently working on implementing a Help functionality for our users. In order to do this, I have placed a div right above my footer. However, I am facing an issue where the styling of my div is affecting the footer in ways that I cannot figure out. ...

Implementation of internationalization into a JSON-formatted data file

I recently integrated i18n into my application and I'm facing a challenge with implementing the useTranslation(); function in my navbar data file. This file serves as the database for the page titles and tabs, and I'm unsure about how to proceed. ...

Automatically update Dropdown options with value and text through an ajax json request

I am working on dynamically populating a dropdown list with text and values fetched using an ajax call to retrieve a JSONObject. While my current code successfully populates the dropdown, I need the value to be different from the text as I intend to store ...

The componentDidUpdate method is functioning by comparing the previous state with the current state on different triggers

I have a primary element that is invoking another element with specific attributes. // Primary Element <SecondaryElement className="EnterNumber-input" submitClicked={this.state.submitClicked} /> Upon clicking a button, I am modify ...

Retrieve the current URL upon page load

I'm currently attempting to parse the URL in document.ready() so I can retrieve the id of the current page and dynamically populate it with content from an AJAX call. However, I've encountered an issue where 'document.URL' seems to refe ...