I have a website that features a Bootstrap 3 navbar. This navbar is positioned 280px below a block div and becomes sticky at the top of the page when scrolled to that point.
HTML (within < head > tags)
<script>
$(document).ready(function() {
var s = $("#nav");
var pos = s.position();
$(window).scroll(function() {
var windowpos = $(window).scrollTop();
if (windowpos >= pos.top) {
s.addClass("stick");
} else {
s.removeClass("stick");
}
});
});
HTML
<div id="nav">
<div class="navbar navbar-default navbar-static">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
...
CSS
header {
height:280px;
}
.stick {
position:fixed;
top:0px;
width: 100%;
}
The navbar sticks to the page correctly when scrolling, but once the 'nav' div has the position: fixed attribute applied, it no longer flows with the content which causes the content to 'jump' up by the height of the navbar.
Any ideas on how to prevent this jumping effect?