Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:08:50+00:00 2026-05-27T04:08:50+00:00

I have a ‘sticky sidebar nav’ that is positioned absolutely relative to the #sidebar

  • 0

I have a ‘sticky sidebar nav’ that is positioned absolutely relative to the #sidebar div, so it follows the page down on the left hand side and is always available. To make this work I had to add a height to the sidebar, so I used some code to find the height of the container dynamically. This is the code i used:

<script type="text/javascript">
    function matchColHeights(col1, col2) {
        var col1Height = $(col1).height();
        var col2Height = $(col2).height();
        if (col1Height > col2Height) {
            $(col1).height(col2Height);
        } else {
            $(col1).height(col2Height);
        }
    }

    $(document).ready(function() {
        matchColHeights('#sidebar', 'section#main-container');
    })
</script>

Currently the #sidebar div sits inside the section called section#maincontainer. A very simplified version of the html is below.

<body>
    <header>Header content</header>
    <section id="main-container">
        <div id="sidebar">
            <ul>
                This is the floated ul
            <ul>
        </div>
        <div class="content">
            This is where the content of the page sits
        </div>
        <div class="content2">
            This is where the content of the page sits (because of the design there are often more than one divs floated right
            <div>Within the content divs are potential expanding divs (accordions and tabs that change size)</div>
        </div>
    </section>
    <footer>Footer content</footer>
</body>

So the problem I have is that there is expandable content (tabs and accordions) in the content area, and when the content expands, the jQuery does not update the height of the sidebar to the new height (this new height could be shorter or longer than the original height). I have tried adding the function to my .click() handler of the accordion (haven’t yet tried with the tabs) but here is the code that is used to drop my accordion down:

<!--Content Accordion-->
<script type="text/javascript">
    $(document).ready(function() {
        $('div.content-accordion> div').hide();  
        $('div.content-accordion> h4').click(function() {
            var $nextDiv = $(this).next();
            var $visibleSiblings = $nextDiv.siblings('div:visible');

            if ($visibleSiblings.length ) {
                $visibleSiblings.slideUp('fast', function() {
                    $nextDiv.slideToggle('fast');
                    $matchColHeights('#sidebar', 'section#main-container');
                });
            } else {
                $nextDiv.slideToggle('fast');
                $matchColHeights('#sidebar', 'section#main-container');
            }
        });
    });
</script>

As you can see I can add the $matchColHeights('#sidebar', 'section#main-container'); function into the click function and it doesn’t refresh to the new height still. I have tried a few other possibilities with no luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:08:51+00:00Added an answer on May 27, 2026 at 4:08 am

    Just to let everyone know i found a solution…Took alot of messing about but code is below.

    I essentially on the click had to set sidebar height back to 0, and create a function that finds the new height of the section#main-container, and then applys that as a css height to the sidebar. This changed the height of the sidebar just fine, but then the sticky sidebar wasnt readjusting to the new height, so i just pasted the code that works my sticky sidebar (the code that starts with $(“aside”) into the function and it refreshes just fine. Thanks to those that helped.

    <!--Content Accordian-->
    <script type="text/javascript">
    $(document).ready(function() {
      $('div.content-accordian> div').hide();  
      $('div.content-accordian> h4').click(function() {
        var $nextDiv = $(this).next();
        var $visibleSiblings = $nextDiv.siblings('div:visible');
    
        if ($visibleSiblings.length ) {
          $visibleSiblings.slideUp('fast', function() {
            $nextDiv.slideToggle('fast', function() {
    // START CHANGE SIDEBAR HEIGHT      
            $("#sidebar").css({ height: 0});
            newheight = $("section#main-container").height();
             $("#sidebar").css({ height: newheight});
             $("aside").stickySidebar({
                timer: 500
              , easing: "easeInOutQuint"
              , constrain: true
            });
    
          });
    // END CHANGE SIDEBAR HEIGHT    
          });
        } else {
           $nextDiv.slideToggle('fast', function() {
    
    // START CHANGE SIDEBAR HEIGHT      
            $("#sidebar").css({ height: 0});
            newheight = $("section#main-container").height();
             $("#sidebar").css({ height: newheight});
             $("aside").stickySidebar({
                timer: 500
              , easing: "easeInOutQuint"
              , constrain: true
            });
    
          });
    // END CHANGE SIDEBAR HEIGHT
        }
      });
    });
    </script>   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
have 2 questions : A computer with 32-bit address uses 2-level page table (9
Have a simple form that has a PictureBox in one location. I want to
Have a photography site that I want to prevent image copying from. How can
Have a problem that seems easy on paper but i'm having a big problem
Have a look at this HTML code: <div class=overlay> <a href=#>1</a> <a href=#>1</a> <a
Have a query that should hopefully be nice and simple to answer. I have
Have a web service that implements REST (sort of) , Client request is made
Have a look at this JSFiddle: http://jsfiddle.net/kZ3Af/25/ I have the base navigation pinned down
Have an app that can use tts to read text messages. It can also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.