Scrollbars in Jquery are not visible anymore when adjusting the size of a div element, causing them to expand

I'm facing an issue with a layout containing a div that expands to the screen size upon clicking a button. Initially, the div has enough content to necessitate scrolling. However, after collapsing back to its original size, the scroll bar disappears and some content becomes hidden.

What could be causing this unexpected behavior? I attempted to address it by reapplying the overflow auto CSS within the toggle function, but unfortunately, it didn't resolve the problem.

<?xml version="1.0" encoding="utf-8" ?>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">

<title>Untitled 2</title>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function() {
    var height = $( window ).height();
    var width = $( window ).width();
    canvasHeight = height - 282;
    $("#mainCanvas").css({"height" : canvasHeight});
    $("#header").css({"min-width" : width});
    $("#mainCanvas").css({"min-width" : width});
    $("#legend").css({"min-width" : width});
    $("#footer").css({"min-width" : width});

    $("#toggle").click(function() {
            if($("#mainCanvas").height() != height) {
                $("#header").hide();
                $("#legend").hide();
                $("#footer").hide();
                $("#detail").animate({"top" : '0px'});
                $("#toggle").animate({"top" : '0px'});
                $("#mainCanvas").animate({"height": height}, {"queue": false, "duration": 500}).animate({"width": width}, 500);
                $("#toggle").html('<img id="expand" src="img/collapse.png">');
            }
            else {
                $("#mainCanvas").animate({"height": canvasHeight}, {"queue": false, "duration": 500}).animate({"width": '100%'}, 800); 
                $("#header").show();
                $("#legend").show();
                $("#footer").show();
                $("#detail").animate({"top" : '92px'});
                $("#toggle").animate({"top" : '92px'});
                $("#toggle").html('<img id="expand" src="img/expand.png">');
            }
        }); // End Expand/Collapse

});
</script>

<style type="text/css">
html, body {
    padding: 0;
    margin: 0;
}
img#expand {
    width: 20px;
    cursor: pointer !important;
    margin-left: 7px;
    margin-top: 2px;
}

/* Application Details */
div#toggle {
    left: 95%; 
    top: 92px; 
    width: 34px;
    height: 29px;
    border: 1px solid #ccc;
    background: white;
    padding-top: 5px; 
    position: fixed;
}

</style>
</head>

<body> 

...

Answer №1

It seems that jquery is changing the overflow css property of the #mainCanvas to hidden for some unknown reason. To temporarily resolve this issue, you can reset it to "auto" within the complete argument of the animate function:

    $("#toggle").click(function() {
            if($("#mainCanvas").height() != height) {
                $("#header").hide();
                $("#legend").hide();
                $("#footer").hide();
                $("#detail").animate({"top" : '0px'});
                $("#toggle").animate({"top" : '0px'});
                $("#mainCanvas").animate({"height": height}, {"queue": false, "duration": 500}).animate({"width": width}, 500,function() {
$(this).css("overflow","auto")
});
                $("#toggle").html('<img id="expand" src="img/collapse.png">');
            }
            else {
                $("#mainCanvas").animate({"height": canvasHeight}, {"queue": false, "duration": 500}).animate({"width": '100%'}, 800,function() {
$(this).css("overflow","auto")
}); 
                $("#header").show();
                $("#legend").show();
                $("#footer").show();
                $("#detail").animate({"top" : '92px'});
                $("#toggle").animate({"top" : '92px'});
                $("#toggle").html('<img id="expand" src="img/expand.png">');
            }
        }); // End Expand/Collapse

(tested and works in IE 8.0)

Answer №2

just the adjusted otherwise section

otherwise {
        $("#mainCanvas").css('overflow','auto', 'important');
        $("#mainCanvas").animate({"height": canvasHeight}, {"queue": false, "duration": 500}); 
        $("#header").show();
        $("#legend").show();
        $("#footer").show();
        $("#detail").animate({"top" : '92px'});
        $("#toggle").animate({"top" : '92px'});
        $("#toggle").html('<img id="expand" src="img/expand.png">');      
}

Interactive JS Fiddle Example

Answer №3

Consider incorporating the following code snippet within your conditional statement:

$("#content p").css({"overflow": 'scroll'});

Explore this example on JSFiddle

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 way to retrieve the selected drop down value using AJAX in PHP?

I'm facing an issue with the ajax drop down where the selected value is not retained after editing or refreshing. <div class="form-group" id="maincat"> <label for="cat_desc" class="col-sm-2 control-label">Select Stat ...

Stop the execution of the setTimeout function when the webpage loads in JavaScript

In my postgres database, I have a table named students for storing student information. The structure of the table is as follows: id first_name last_name time_remind 1 pers1 pers1_name 2022-07-30 21:30 2 pers2 pers2_name 2022-07-30 20:38 Current ...

Tips for dynamically passing a URL to a function using the onload event

I require assistance with passing a dynamic URL to a function. code onload="getImage('+ val.logo +');" onclick="loadPageMerchantInfo('+ val.merchant_id +'); The value of val.logo contains a URL such as: https://www.example.com/upload ...

Retrieving JSON information from asynchronous JavaScript and XML (AJAX)

I am struggling with making a URL that contains JSON Data work properly. The issue lies in the data field - I am unsure of what to input here as it is currently undefined. My goal is to store an array of the JSON data received from the ajax request. What ...

Utilize jQuery to showcase elements in a dropdown menu

Hey everyone, I'm working on an ASP.NET MVC4 project and I'm using a jQuery script on the edit page. However, I am encountering an issue with displaying elements on the page. Here is the initial HTML markup of my dropdown before any changes: & ...

Iterating through a SASS map and retrieving the next item in the loop

I am working with a color array that looks like this: $colors: ( 'primary': '#aaa', 'secondary': '#bbb', 'color-3': '#ccc', 'color-4': '#ddd', 'color-5': & ...

Struggling to locate div#ID from the loaded fixtures with the Jasmine JS Framework

I successfully loaded my fixtures by using the following code: var fixture = loadFixtures("path/fixture.html"); Now, I am attempting to identify a specific DIV element with the ID #ID using the script below: expect(fixture.find('DIV#ID')).toBe ...

What is the best way to ensure a consistent spacing between two flex items?

I am working on a project to enhance my knowledge by rebuilding Facebook. One of the new concepts I am learning is Flexbox. When you resize the login page of Facebook, you'll notice that the Navigation shrinks but the logo and login inputs remain sta ...

Loading slides in bxSlider using ajax

Is there a method to dynamically insert a slide into bxSlider via ajax without affecting its smooth transition? I am looking to initially display the contents of only one slide upon page load, and then have subsequent slides loaded when the next or previo ...

jQuery can be used to relocate buttons on a webpage

When the Contact button is clicked, how can I move the Close button below #panel? It's currently fixed in position. Here's my demonstration: https://jsfiddle.net/25u78gff/ jQuery('.sub-menu').addClass('dropdown-menu'); jQ ...

Manipulating nested arrays using index values in JavaScript

Can someone assist me in sorting a multidimensional array based on the value of the first index? I've tried using a for loop without success. Looking for solutions in JS or jQuery. I want to convert the following array: var pinData = [ ['< ...

Is there a way to horizontally navigate a pallet using Next and Prev buttons?

As someone new to development, I am looking for a way to scroll my question pallet up and down based on the question number when I click next and previous buttons. In my pallet div, there are over 200 questions which are dynamically generated. However, th ...

A guide on how to initiate a click event in Angular 5 using JQuery

I am trying to trigger a click event for each element based on its id, but it doesn't seem to be working. Below is the code I am using: ngOnInit() { this.getProductsLists(); } getProductsLists() { this.supplierService.getProductLists() .sub ...

Tips for showcasing a search bar on Google search results

While browsing in Google, I came across websites that have a search bar displayed after their initial search result. This functionality allows users to easily search within the website as shown in the image below. I am intrigued and wondering how this can ...

What is the significance of the A tag when parsing a URL?

So, I encountered a problem that involved parsing a URL to extract the hostname and pathname, then comparing the extracted pathname with a string. If you need help with this issue, check out this post: How do I parse a URL into hostname and path in javasc ...

Showing Variables in JavaScript

<!DOCTYPE HTML> <html> <body> <button onclick="question++">Increment</button> <script> function test() { var question = 0; } </script> </body> </html> Qu ...

Struggling to transfer an image to a Linux server using Phonegap and PHP

An application being developed using PhoneGap requires an image to be uploaded to a Linux server. To test this process, a CentOS 7 VM was set up and the LEMP stack was installed and configured on it. A php script named upload.php was created (shown below), ...

What is the best way to ensure that the search box automatically adjusts its position and size regardless of the screen resolution?

I'm currently working on a responsive website project and facing an issue with the absolute positioning of the search bar on the main page, which is crucial for me. Below is the code snippet: <div class="span4"> <form class="well form ...

Using jQuery, selectively reveal and conceal multiple tbody groups by first concealing them, then revealing them based on

My goal is to initially display only the first tbody on page load, followed by showing the remaining tbody sections based on a selection in a dropdown using jQuery. Please see below for a snippet of the code. //custom JS to add $("#choice").change(func ...

Applying binary information to an image

Let's say I have an <img/>. The img is initially set with src='http://somelocation/getmypic'. Later on, there might be a need to change the content of the image based on some ajax call that returns binary data. However, this decision c ...