The scrollbar remains unresponsive and fixed until the screen size is adjusted

Need some assistance with a website project for a client. The scrollbars on each page are not loading or changing height until the window is resized. I have a jQuery scrollbar in place, but disabling it does not solve the issue as the normal scrollbar behaves the same way. The content is within a child div of the scrolling div, but the height of the content div remains static even when the content changes. Trying to turn the code from $(window).resize into its own function has not been successful.

It's quite frustrating and annoying to deal with this.

EDIT: Added the complete JS code with edits as advised by Max Dunn, but the issue persists.

        //--details
        $(document).ready(function() {
            $("#info").show();
        });
        $(document).ready(function() {
            $('#elephant').click(function() {
                if ($('#info').css('display') == "none")
                    $('#info').fadeIn('slow'),
                    $('#stay').hide();
                    $('#todo').hide();
                    $('#nav').hide();
                    $('#gifts').hide();
                    $('#contact').hide();
                    $('#photos').hide();
                    $('#welcome').hide();
                    $("#bubblecontent").show();
                    resizeBubble();
            });
        });
        ... // rest of the JS code follows

    body {
        overflow-y: hidden;
        overflow-x: hidden;
        font-family: "museo-slab", georgia, serif;
        font-weight: 100;
        height: 100%;
    }
    #container {
        margin-left: auto;
        margin-right: auto;
    }
    #bubble {
        background-color: #f5fec3;
        height: 100%;
        width: 900px;
        margin-left: auto;
        margin-right: auto;
        border-radius: 15px;
        -moz-border-radius: 15px;
        overflow-y: auto;
    }
    #bubblecontent {
        width: 860px;
        margin-left: auto;
        margin-right: auto;
        overflow-y: auto;
    }

<div id="container">
  <div id="bubble">
    <div id="bubblecontent">
      <div id="contentdiv1">
        blah
      </div>
      <div id="contentdiv2">
        blah
      </div>
    </div>
  </div>
</div>

Answer №1

Keeping my original response for the benefit of others facing a similar issue, I took a deeper look at the provided javascript code and made significant improvements by revising the code structure. The key modification involved utilizing the mCustomScrollbar("update") function upon content alterations:

<script type="text/javascript">
  // Page loading
  $(window).load(function () {
    $('#loading').fadeOut('fast');
  });

  $(document).ready(function () {
    // Preloading images
    loadImage1 = new Image();
    loadImage1.src = "http://static.tumblr.com/spps9en/JN3m8jui6/elephanthover.png";
    staticImage1 = new Image();
    staticImage1.src = "http://static.tumblr.com/spps9en/j7Fm8jufs/elephant.png";

    // Additional image preloading here

    function resizeBubble() {
      var divHeight = $(document).height() - 300;
      $('#bubble').css({height: divHeight});
    };

    $(window).resize(function () {
      resizeBubble();
    });

   // More functionality added below...

</script>

Answer №2

Start by converting the code for resizing into a separate function:

function adjustSize() {
  var windowHeight = $(window).height() - 300;
  $('#bubble').css({height: windowHeight});
};

Next, make sure to invoke this function after revealing the initial hidden div.

$(document).ready(function() {
  $("#info").show;
  adjustSize();
};

This step is important because you can't predict the order in which $(document).ready will execute, and it may happen before any divs are displayed.

Don't forget to include the call to adjustSize() at the end of each click event function and whenever $(window).resize occurs.

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

MUI useStyles/createStyles hook dilemma: Inconsistent styling across components, with styles failing to apply to some elements

I have been trying to style my MUI5 react app using the makeStyles and createStyles hooks. The root className is being styled perfectly, but I am facing an issue with styling the logoIcon. Despite multiple attempts to debug the problem, I have not been suc ...

[widget name] is not ready to execute methods yet

Despite initializing my plugin successfully, I keep encountering the error message cannot call methods on collapsableTabs prior to initialization whenever I attempt to invoke a method in the plugin. The plugin is properly loaded and displaying as expected ...

How can I convert a background image source into a fluid list item with a display property of inline-block?

I have a unique image with dimensions width: 656px and height: 60px that serves as the background for my menu. Each menu button has a specific position within the image, for example, the menu button for 'media' is located at (188x, 0y), with a wi ...

Responsive design for iPads and smartphones is essential in ensuring a seamless user

Currently in the process of creating my own personal website, I have been diligently using Chrome Canary to ensure that all my media queries are properly set up. While everything looks great on Canary and functions well in various device modes within the b ...

Using jQuery or JavaScript, extract JSON data from Yahoo Pipes

Here is the JSON format that I receive from Yahoo pipes: {"count":3, "value":{ "title":"Freak count feed", "description":"Pipes Output", "link":"http:\/\/pipes.yahoo.com\/pipes\/pipe.info?_id=565sdf6as5d4fas ...

Hero Sticky Transition with 100vhDivElement

My code is giving me some trouble. I want the div with text to stay at the bottom of the hero section with a transparent background. When that div reaches the top, it should stick with a black background. The issue is that I have set it in the javascript v ...

The request made to `http://localhost:3000/auth/signin` returned a 404 error, indicating that

My goal is to access the signin.js file using the path http://localhost:3000/auth/signin Below is my code from [...nextauth].js file: import NextAuth from "next-auth" import Provider from "next-auth/providers/google" export default N ...

Using jQuery to enhance the functionality of the drop-down select feature

I am facing an issue with my index file code. When I select something from the drop-down menu, I expect to see a related dropdown appear. Although I have added this code to my file, I am unable to get the drop down to show after selecting the main type. ...

A growing flexbox container that expands to a specific height before allowing for scrolling

In the case of a fixed height container with two vertical divs, I am aiming for the first div to be as tall as its content, up to 80% of the parent div's height. After that point, the content within the first div should scroll. The second div will the ...

waiting to display information until it is necessary

I am currently working on optimizing my website for improved loading speed and responsiveness. Users can scroll through up to 4k images, apply filters, and sort them based on their preferences. Below is the code snippet for my filtering function: function ...

Ways to deactivate the submit button using Cookies, sessions, or local storage

Although cookies and storage can be deleted, they can still help prevent many human spammers who are unaware of this. How can I temporarily disable the form submit button on a specific page for just one day? I want to create a code that saves "Submitted" ...

Drag a dropdown menu to the bottom left corner and set it to full width on mobile using CSS

Check out this code snippet with CSS and HTML: CSS .flyout { position: absolute; top: 30px; right: 15px; background-color: #FFF; padding: 20px; border: 1px solid #eaeaea; z-index: 999; width: 400px; border-top: 3px solid #337AB7; disp ...

Is it possible to implement formvalidation.io in a React project that is using Materialize-css?

Can the formvalidation.io plugin be used with React and Materialize-css in a project? My project consists of multiple input components that may or may not be within a form. I want to utilize formvalidation for input validation. However, I am unable to find ...

Preview and crop your image before uploading

Currently, I am working on developing a form that will enable administrators to upload an image. The aim is to allow them to preview the image before uploading it, displaying it at a specific size and providing the option to click on the image to open an i ...

The express-handlebars module is having trouble parsing HTML within the main layout file in an Express.js application

Hello, I am facing an issue with handlebars as it is not reading the HTML in my file. Here is a screenshot highlighting the problem along with the provided code. The folder structure is as follows: views layouts main-layout.hbs home.hbs https://i ...

Is it possible for the upload form submission to wait until the file processing is finished?

Is it possible for the form submission to wait until the file processing is complete? I am currently using web2py and its sqlform to upload a video file. As the file is being uploaded, it is also being converted to flv format. The progress of both uploadi ...

Guide to integrating various HTML files into a single HTML file with the help of Vue.js

Although I am familiar with using require_once() in PHP, unfortunately, I am unable to use PHP in my current project. I attempted to use w3-include from W3Schools as an alternative, but encountered issues with loading my scripts. Even utilizing JavaScript ...

Passing an undefined value to the database via AJAX upon clicking a button

Hi there, I'm currently working on a table where I'm trying to perform an inline edit and update the value in the database by clicking on a button (an image). I've attempted to use an onclick function, but it seems to show "value=undefined&a ...

Utilizing margins in CSS for various div elements

Update: I have included Javascript and Masonry tags in my project. Despite having modules of the same size, I am exploring how masonry can assist me. However, I find it a bit puzzling at the moment as I am not aiming to align elements of different sizes. I ...

"Exploring the Power of Jsoup for Selecting

I'm attempting to extract all the links nested within the div class news column index. Here is a snippet of the HTML structure: https://i.stack.imgur.com/zdFWS.jpg Below is the code I have used, but unfortunately, it's not yielding any results. ...