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

  • Home
  • SEARCH
  • 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 8753187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:22:52+00:00 2026-06-13T13:22:52+00:00

The bootstrap documentation on that topic is a little confusing to me. I want

  • 0

The bootstrap documentation on that topic is a little confusing to me. I want to achieve similar behaviour like in the docs with the affix navbar: The navbar is below a paragraph / page heading, and upon scrolling down it should first scroll along until reaching the top of the page, and then stick there fixed for further scrolldowns.

As jsFiddle does not work with the navbar concept, I’ve set up a separate page for usage as a minimal example: http://i08fs1.ira.uka.de/~s_drr/navbar.html

I use this as my navbar:

<div class="navbar affix-top" data-spy="affix" data-offset-top="50">
    <div class="navbar-inner">
        <div class="container">
            <div class="span12">
                <a class="brand" href="#">My Brand</a> 
                This is my navbar.
             </div>
        </div> <!-- container -->
    </div> <!-- navbar-inner -->
</div> <!-- navbar -->

I thinkg i would want data-offset-top to be of value 0 (since the bar should “stick” to the very top” but with 50 there is at least some effect watchable.

If also put the javascript code in place:

     <script>
        $(document).ready (function (){
            $(".navbar").affix ();
        });
     </script>

Any help appreciated.

  • 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-13T13:22:53+00:00Added an answer on June 13, 2026 at 1:22 pm

    I was having a similar problem, and I believe I found an improved solution.

    Don’t bother specifying data-offset-top in your HTML. Instead, specify it when you call .affix():

    $('#nav').affix({
        offset: { top: $('#nav').offset().top }
    });​
    

    The advantage here is that you can change the layout of your site without needing to update the data-offset-top attribute. Since this uses the actual computed position of the element, it also prevents inconsistencies with browsers that render the element at a slightly different position.


    You will still need to clamp the element to the top with CSS. Furthermore, I had to set width: 100% on the nav element since .nav elements with position: fixed misbehave for some reason:

    #nav.affix {
        position: fixed;
        top: 0px;
        width: 100%;
    }
    

    One last thing: When an affixed element becomes fixed, its element no longer takes up space on the page, resulting in the elements below it to “jump”. To prevent this ugliness, I wrap the navbar in a div whose height I set to be equal to the navbar at runtime:

    <div id="nav-wrapper">
        <div id="nav" class="navbar">
            <!-- ... -->
        </div>
    </div>
    

    .

    $('#nav-wrapper').height($("#nav").height());
    

    Here’s the obligatory jsFiddle to see it in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using a default/vertical form, the bootstrap documentation suggests that the submit button sits underneath
According to the twitter bootstrap documentation , I should be able to Wrap strings
The Bootstrap .dropdown-menu.pull-right selector doesn't seem to work (the code is in navbar.less, lines
Twitter Bootstrap has a form control that would glow on the borders when in
I am using twitter bootstrap and I would like a container div to stretch
I'm using Bootstrap on a web app that has some pages that contain iframes.
i'm using twitter bootstrap 2.0.4. i want to populate the dropdown using ajax. the
I'm looking into Bootstrap and am wondering about offsetting columns: http://twitter.github.com/bootstrap/scaffolding.html#gridSystem The documentation says
https://developers.google.com/maps/documentation/javascript/libraries In the documentation,its given that java-script code for maps API can be loaded
respond.js or css3-mediaqueries.js ? The official documentation, especially that of css3-mediaqueries.js, is sparse. Reading

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.