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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:56:52+00:00 2026-05-30T01:56:52+00:00

The idea: I’m creating a div that will change to position:fixed once the top

  • 0

The idea:

I’m creating a div that will change to position:fixed once the top of the div touches the top of the browser window, so that the div appears to float. An example of this behavior and the code to make it work can be found here: Creating a sometimes fixed position element.

The problem:

The site where I’m implementing this code has a pretty hefty footer on it, so the position: fixed div, if the browser window is short enough, will scroll over the footer. The ideal behavior would be for the position: fixed div to not scroll past the footer and to instead bottom out. I haven’t gotten that far quite yet. Currently I’m doing a check for if the #fixie_container bottom is past the .footer_container top, if it is then I’m removing the position: fixed property from the #fixie_container by removing the .fixie_container_fixed class. This is causing problematic behavior though. Once the bottom of the #fixie_container is past the .footer_container top, the .fixie_container_fixed class is removed and then added rapidly causing the #fixie_container to flicker rapidly.

I obviously have a bug in my logic somewhere but, being new to JS/JQ, I’m not sure what it is. Any pointers would be greatly appreciated.

The HTML:

I have a page with a body and a small right column. The floating div is located at the bottom of the right column. When the top of the div hits the top of the viewtop, then the position: fixed attribute is applied.

<div id="fixie_placeholder">
    <div id="fixie_container">
        THIS CONTENT WILL HOVER                    
    </div>
</div>
<div class="footer_container">
    THIS IS THE FOOTER
</div>

The CSS:

#fixie_placeholder {
    position: relative;    
}
#fixie_container {
    z-index: 9999999;
    width: 300px;
}
div.fixie_container_fixed {
    position: fixed;
    top: 0;
}

The JQuery:

<script type="text/javascript">
jQuery(function($){

    var placeholder = $("#fixie_placeholder");
    var container = $("#fixie_container");
    var block = $(".footer_container");
    var view = $(window);

    view.bind("scroll resize", function(){

        var placeholderTop = placeholder.offset().top;
        var containerBottom = container.offset().top + container.height();
        var blockTop = block.offset().top;
        var viewTop = view.scrollTop();

        if ((viewTop > placeholderTop) && !container.is(".fixie_container_fixed") && (containerBottom < blockTop)){

            placeholder.height(placeholder.height());

            container.addClass("fixie_container_fixed");

        } 
        else if ((viewTop <= placeholderTop) && container.is(".fixie_container_fixed") || (containerBottom >= blockTop)){

            placeholder.css("height", "auto");

            container.removeClass("fixie_container_fixed");

        }
    });

});
</script>
  • 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-30T01:56:53+00:00Added an answer on May 30, 2026 at 1:56 am

    Check out this jsFiddle: http://jsfiddle.net/pseudosavant/AFqBM/

    I’m just making the header position:fixed when the document is scrolled past the header, and returning it back to position:relative (via a css class) when the user scrolls above the header or it reaches the top of the page. To make it stay behind the footer I set the footer to be z-index: 10000 and position:absolute and put it inside a container div that is position:relative so that it is still placed at the end of the page.

    Javascript:

    $(document).ready(function(){
        $(window).bind("scroll resize", function(){
            var scrollTop = $(window).scrollTop();
            var headerTop = $("#header").offset().top;
    
            if (scrollTop >= headerTop && scrollTop !== 0) { // Scrolled past top of header, but not at the top of the page
                $("#header").addClass("fixed");
            } else {
                $("#header").removeClass("fixed");            
            }            
        });
    });
    

    CSS:

    #container { padding-top: 25px; }
    #header, #content, #footer { width: 400px; }
    #header { z-index: 9999; top: 0;
              background: blue; }
    #header.fixed { position: fixed; }
    #content { background: green; }
    .box { width: 300px; height: 300px; background: purple; display: inline-block; }
    #footerContainer { height: 400px; position: relative; }
    #footer { background: red; z-index: 10000; position: absolute; }
    

    HTML:

    <div id="container">
        <div id="header">
            Header
        </div>
        <div id="content">
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
        </div>
        <div id="footerContainer">
            <div id="footer">
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
                Tall Footer<br/>
            </div>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any idea on how to check whether that list is a subset of another?
The idea is that there is a primary implementation of COM interface, which needs
The idea here is that for my testing, before I commit to purchasing the
The idea here is to have a python app, that when started, asks for
Simple idea: I have two images that I want to merge, one is 500x500
Any idea how to render a PDF using iTextSharp so that it renders the
Any idea how to initialize .NET delegate that points to method from 'mixed' class
Any idea why the following code will not compile? IEnumerable users; using (var ent
Any idea to make an element in the page full screen? For example,a div
The idea of my simple program that I've been trying to write is to

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.