KEY , select , , FIXED , - , . CSS. jQuery 1.11 , , , , . . , for, jquery each , for - each. , , , , , DOM...
, , , , , , getBoundingClientRect . , .
var pos,
$el = $('#select'),
navItems = $el.find('.nav'),
menuHeight = $el[0].clientHeight,
scrollY,
sections = $('.section').toArray(),
pointOfAttachment = $('.jumbo')[0].clientHeight - menuHeight;
$(window).on('scroll.nav', updateNav)
.on('resize.nav', updateNav);
function updateNav(){
scrollY = window.pageYOffset || document.documentElement.scrollTop;
for( var i = sections.length; i--; ){
if( sections[i].getBoundingClientRect().top < 0 ){
navItems.filter('.' + sections[i].id).addClass('active').siblings().removeClass('active');
break;
}
navItems.removeClass('active');
}
if( scrollY > pointOfAttachment )
$el.addClass('fixed');
else
$el.removeClass('fixed');
}
?
, DOM , . , DOM, , .