var $block = $('nav'),
position = $block.offset().top;
$(window).scroll(function(){
if ($(window).scrollTop() > position) {
$block.addClass('fixed');
} else {
$block.removeClass('fixed');
}
});
var $block = $('nav'),
var position = $block.offset().top;
$(window).on('resize', function() {
position = $block.offset().top
});
$(window).scroll(function(){
if ($(window).scrollTop() > position) {
$block.addClass('fixed');
} else {
$block.removeClass('fixed');
}
});
<nav></nav>
<div.nav-wrapper> <nav></nav> </div>