Content within a scrollable div in IE7 only loads once the user starts scrolling

TL;DR: How can I make IE7 load all hidden elements within a scrollable div?

I'm creating a collapsible menu for easy navigation through a series of pages. This menu has two states: collapsed and expanded.
Think of the menu items as chapters in a book, with the 'active' menu item moving down as the user progresses through the content.
Upon page load, I want the <div> containing the items to instantly scroll down to the active menu item, with a slight offset.

This works flawlessly on Chrome and Firefox, but IE7 is causing some trouble.

In the expanded state, it seems that IE7 doesn't bother loading items that are not initially visible. What happens is that IE7 starts the menu div without a scrollbar (or a very small one). When I set the scrollTop to the required amount, the div just scrolls down until the scrollbar hits the bottom, prompting IE7 to start loading the next bit of content so I can continue scrolling down, repeating this process.

To work around this issue, I used an animation with a duration of 1000ms (just picked a number). While it's not ideal and looks rough, I need to figure out how to force IE7 to load this content before it's needed since it's failing to do so on its own.

We have a significant number of IE7 users, so skipping this problem isn't an option. Additionally, making the content accessible to users without JavaScript is a big priority.

In the collapsed state, there are no issues. I attempted to apply parts of the collapsed state's CSS to the expanded state temporarily, but it didn't resolve the problem.

Here's some code:

scrollToCurrent = function(length){
    var prev = $("div.scroller div.selected").prev();

    // Check if previous exists
    if($(prev).length > 0) {
        // Calculate scroll position based on previous items
        var scrollY = ($(prev).prevAll().length * $(prev).outerHeight()) - ($(prev).outerHeight() / 2);

        if(length === 0) {
            $("div.scroller").scrollTop(scrollY);
        } else {
            $(".scroller").animate({
                scrollTop : scrollY
            }, length);
        }
    }
};

If you need more information, please let me know.

EDIT: Basic jsfiddle: http://jsfiddle.net/AmazingDreams/keeUY/ http://jsfiddle.net/AmazingDreams/keeUY/embedded/result/

Answer №1

UPDATE

After numerous failed attempts to fix the issue with the scrollbar, I resorted to a simple solution. Frustrated by the constant back and forth of trying different fixes that only seemed to cause more problems, I decided to take a brute force approach:

I got rid of all the old 'fixes'

scrollToCurrent = function(length){
        var prev = $("div.scroller div.selected").prev();

        // Check if previous exists
        if($(prev).length > 0) {
            // number of previous items * height of item - half an items height
            var scrollY = ($(prev).prevAll().length * $(prev).outerHeight()) - ($(prev).outerHeight() / 2);

            if(length === 0) {
                var i = 0;
                var maxpushes = 100;

                // Push just as long as needed to get the scrollbar to where we want it to (fixes ie7 issue)
                while($("div.scroller").scrollTop() < scrollY) {
                    $("div.scroller").scrollTop(scrollY);

                    // Make sure it can never turn into an endless loop
                    i++;
                    if( i > maxpushes) {
                        break;
                    }
                }
            } else {
                $(".scroller").animate({
                    scrollTop : scrollY
                }, length);
            }
        }
    };

OLD NON-WORKING ATTEMPTS

To my surprise, adding an extra item seemed to resolve the issue temporarily: UPDATED FIX BELOW

    <div class="cycle inactive">
        <?php // I fix IE7 issues ?>
    </div>

It appears that simply having this extra line does most of the work in fixing the problem.

Despite this temporary fix, I am not convinced it is the ultimate solution, so I will continue to monitor the stability of the system before closing this question.

EDIT:

Ironically, what I thought was a 'major update' actually made matters worse (imploded stopped working, while exploded worked). Here is the updated fix:

<?php // Only show if menu starts exploded ?>
<?php if( ! $imploded): ?>
    <div class="cycle inactive">
        <?php // I fix IE7 issues ?>
    </div>
<?php endif; ?>

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

Choose specific dates from the data pickers based on the membership tiers and level of importance

I am seeking assistance in implementing a date selection functionality with different priority levels assigned to customers. Below is an explanation of the criteria: Customers with level 1 can choose dates from today up to 5 days in the future Cust ...

Use JavaScript to change the CSS pseudo-class from :hover to :active for touch devices

Looking to eliminate hover effects on touch devices? While it's recommended to use a hover class for hover effects, instead of the hover pseudo-class, for easier removal later on, it can be a challenge if your site is already coded. However, there&apo ...

There was an issue encountered while parsing the JSON data - "SyntaxError: Unexpected token . was caught."

Encountering an error in Chrome while parsing JSON data. The JSON sample can be found at this link. It is valid JSON and the server is sending the correct Content-Type value (application/json). Uncaught SyntaxError: Unexpected token . Firefox shows a sli ...

Is there a way to showcase jQuery AutoComplete search outcomes within a <table> instead of a <ul>?

Currently, I am utilizing jQuery UI Autocomplete 1.8.11. My current setup involves using the Remote with Caching mode, which means that each autocomplete call is making a trip to the server. My preference would be to have my own HTML table returned instea ...

Verify if the specified value is present in the dropdown using AngularJS

Utilizing AngularJS, I have implemented an input field with autocomplete functionality. The autocomplete feature pulls data from a JSON file and displays it in a dropdown table format. Users are able to filter the results and select a value from the dropdo ...

effective ways to extract objects from nested structures using a specific identifier

In this sample data, I am looking to filter an object based on its ID key let myData = { "nodeInfo": { "9": { "1": { "ID": "14835" ...

Tips for redirecting to the index page instead of the login form after pressing the back button on the navigation

Hey everyone! I've been struggling with a problem for the past 4 hours and could really use some help. After logging in, the page redirects to a certain page, but when I press the back button in my browser, I want it to redirect back to that specific ...

Ensure chip component (div) dynamically resizes its width to accommodate varying lengths of child text elements

I have a main container with two child elements (a text span and an image svg) created using the Material UI component library. My objective is to dynamically adjust the width of the chip based on the length of the text content inside it, while ensuring a ...

Utilizing the change function in conjunction with that

My attempt at creating a simple function to implement the change function didn't go as planned:/ What I am trying to achieve: 1- When a cost checkbox is checked, assign the corresponding cost (e.g., cost1.checked ? cost1 = 10 : 0) 2- Calculate and di ...

Styling with CSS: How to Show an Absolutely Positioned Element in Google Chrome

I'm currently working on a CSS design that involves positioning an image within a span tag. Here's the CSS code I have: .dc-mega-icon { background-image: url(...); display: inline-block; position: absolute; top: 18px; width: ...

Creating circular borders in CSS: A step-by-step guide

Is it possible to create a circular border in CSS? Currently, the shape is square but I would like it to be circular. color: white; left: 52px; position: absolute; top: 65px; padding: 3px; background-color: rgb(0, 195, 255); ...

Add a fresh item to a list using jQuery

Attempting to add a new list item using jQuery. In this scenario, the process works well, but when attempting to retrieve the value of an input field using .val(), no list item is created. http://www.example.com Code snippet: $(document).ready(functi ...

"Creating a dynamic loop in jQuery using JSON data fetched through an AJAX call to

I am a newcomer to Javascript and I am working on a jQuery-ajax-php project that seems to be exhibiting some strange behavior. The functionality works, but only sometimes. Here is my desired sequence of actions: Set up form settings (works) Retrieve JSO ...

flexbox with equal width and height

I have two questions regarding flexboxes but I am unable to find the answers. How can I create 4 boxes with equal width and height, without using the viewport? For instance, if I create a box with 50% width, I want the height to be equal to the width. ...

I desire the div to display based on the conditions set in the PHP file

Hi, I am looking to display the div with ID "msga" when a certain condition is met and show the div with ID "msgb" when another condition is met. Here is my PHP code: if(isset($_POST['aa'])) { echo "a"; } if (isset($_POST['bb']))) { ...

Error in Typescript: The type 'Element' does not have a property named 'contains'

Hey there, I'm currently listening for a focus event on an HTML dialog and attempting to validate if the currently focused element is part of my "dialog" class. Check out the code snippet below: $(document).ready(() => { document.addEventListe ...

jQuery and Easy Dialog

My jQuery Model window has a form inside. Even though I have set autoOpen to false in my dialog, the fields are still visible when the page is created. All forms are contained within a div. This is what my dialog code looks like: $("#dialog-form").dial ...

Encountering a challenge in Angular 8: Unable to locate a supporting object matching '[object Object]'

I am having an issue trying to retrieve the Spotify API from the current user's playlists. While I can see it in my console, when I attempt to insert it into HTML, I encounter the following error: ERROR Error: Cannot find a differ supporting object ...

To activate an underline on text, simply right-click and select "text

All the anchor tags on my website have been styled with text-decoration: none. Additionally, I have added a CSS rule based on a helpful answer: a, a:hover, a:active, a:visited { text-decoration:none; } However, whenever I right-click on a link on my ...

Converting text into HTML format using Nextjs and React

Currently, I am working on a project that involves using Next.js and React. I am considering creating my own component to parse text based on certain conditions, but I am unsure if something similar already exists. My goal is to: Format the content in HT ...