Jquery ナビ固定 スクロール
var nav = $('#navbar-scrollspy'),
offset = nav.offset();
mT = nav.height();
$(window).scroll(function () {console.log(mT);
if($(window).scrollTop() > offset.top) {
nav.addClass('fixed');
$('#contents').css('marginTop', mT + 20); // 20:navのmargin-bottom
} else {
nav.removeClass('fixed');
$('#contents').css('marginTop', 0);
}
});
<div id="navbar-scrollspy">
<ul>
<li><a href="#">メニュー</a></li>
</ul>
</div>
.fixed {
position: fixed;
top: 0;
width: 100%;
z-index: 9999;
}