I'm using DataTables with the FixedHeader extension. I'm using the offsetTop
option for my fixed header, which is useful for making the header stop below my navigation menu at the top.
When I scroll the page, the header row stops where it is supposed to stop (130px from the top of the page), but as you are scrolling you can briefly see two headers, the one that is sticking in place, and the original one.
Is there something I can do so that the header doesn't show up twice? Hopefully that is clear, this is on a development server so I don't have a link to post.
There is indeed a double header appears unless you do your positioning correctly.
I will highlight important parts of the solution.
CSS:
Added
overflow:auto
because.navbar
has20px
bottom margin and this will make#nav-wrapper
the correct size for us to measure later.JavaScript:
The trick here is to adjust
<body>
top padding to compensate for fixed header. Code$(this).height()
measures height of the#nav-wrapper
, that is why settingoverflow:auto
was important in CSS.Also later we need to measure
offsetTop
correctly for FixedHeader extension. Another trick here is that we're measuring the height of the navigation bar without the20px
bottom margin with$('#nav-wrapper .navbar').height()
.DEMO: