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 7785091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:12:01+00:00 2026-06-01T20:12:01+00:00

So i’ve been doing a little searching and I will continue to look, but

  • 0

So i’ve been doing a little searching and I will continue to look, but I figured it’s time to put my question out to the SO community.

I’m working on a little project that involves a fixed header with variable heights. The basic structure is as such:

<header>
  //any amount of elements
  //meaning this will have varying heights
  //I'll also be able to "open" and "close" this header
  //using slideUp and slideDown (because the end height varies I don't want to use animate)
</header>
<section>
  //body content
</section>

As a normal header (i.e. non css ‘position’ed) this would be fine. It would be in the normal context of the html flow and it would interact with the content below it. When the header slides down the sections below it slide down as well and when it slides up the inverse happens of course. It works something like this http://jsfiddle.net/byazaki/7FcJF/

Now if the position on the header is fixed the sections below it won’t be effected by it moving up and down, hence the introduction of a ‘header-spacer’ element that takes its place.

<header>
  //any amount of elements
</header>
<header spacer>
  //in theory this would resize with the 
  //header as it slides up and down to mimic
  //its effect on the other elements in the flow.
</header spacer>
<section>
  //body content
</section>

this sounds pretty simple right? Well normally yes it is, if I knew how big my header would be when it was open and how small it would be when it was closed. For simplicity sake lets just say it’s 0 when it’s closed, so now I need just worry about when it’s open.

Sorry for the long intro but this leads me back to my initial point: If I don’t know the target “height” of my header how do I animate my spacer? doing .slideDown doesn’t work.

One solution I’ve thought of was to do something like this:

function setSpacer() = { spacer.css('height', header.height())};
var interval = setInterval(setSpacer, 10);
header.slideDown(500, function(){
  clearInterval(interval);
});

Sorry if there are syntax errors or anything like that just trying to paint the picture… basically I start setting the spacer height to the header height every 10 millisecs and then when the header is finished animating it clears the interval.

I haven’t implemented this yet, because I was curious if there was a more elegant solution to my problem or perhaps even something to do w/ jQuery animation branch that I don’t know about?

note:
Another thought has been to write a plugin that extends the slideUp()/slideDown()/animate() classes to take an argument that contains 1 or more html elements and mirrors the animation of the target object.

any thoughts or feedback would be much welcome, thank you 😀

  • 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-06-01T20:12:02+00:00Added an answer on June 1, 2026 at 8:12 pm

    It’s a bit unclear what you want.

    .slideDown()/.slideUp() are used to display and hide content, there is no in between height setting. If you want to decide your own height, I suggest you use .animate() instead.

    This is how I interpreted the question

    I gave the main header a position: fixed and made another <header id="spacer"></header>.
    At the beginning, I register the default height of the main header and give the same height to the spacer. Then I temporarily add a class full_height, which basically is just a height: auto and register the height when it has that class. From thereon things should be simple. Either use slideDown or slideUp on both elements, or use .animate() on both elements to mess with default/full height.

    With that being said, here are both examples using slideDown/slideUp and .animate

    .slideDown()/.slideUp()

    Example | Code

    //The full_height class is just a "height: auto"
    var defaultHeight = $("#header").outerHeight(),
        entireHeight = $("#header").addClass("full_height").outerHeight();
    
    $("#header").removeClass("full_height");
    $("#spacer").height(defaultHeight);
    
    $('#button').click(function() {
        if ($('#header').hasClass('hidden')){
          $('#header, #spacer').slideDown().removeClass('hidden');
        } else {
          $('#header, #spacer').slideUp().addClass('hidden');
        }
    });
    

    .animate()

    Example | Code

    //The full_height class is just a "height: auto"
    var defaultHeight = $("#header").outerHeight(),
        entireHeight = $("#header").addClass("full_height").outerHeight();
    
    $("#header").removeClass("full_height");
    $("#spacer").height(defaultHeight);
    
    $('#button').click(function() {
        if ($('#header').hasClass('hidden')){
            $('#header, #spacer').animate({
                height: defaultHeight //either use default height or entire height
            }, 500).removeClass('hidden').show();
        } else {
            $('#header, #spacer').animate({
                height: 0, //either use default height or 0
            }, 500, function(){
                $(this).hide(); //hide if you're going to use 0
            }).addClass('hidden');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.