//jQuery to collapse the navbar on scroll //$(window).scroll(function() { // if ($(".navbar").offset().top > 50) { // $(".navbar-fixed-top").addClass("top-nav-collapse"); // } else { // $(".navbar-fixed-top").removeClass("top-nav-collapse"); // } //}); var affixElement = '#navbar-main'; //if scrolled pass menu snap, add margin to intro body so when the menu snaps, first section doesn't move up //also snap menu to top under header by adding fixed position and top offset with header height $(window).scroll(function () { if ($(document).scrollTop() > ($("#intro").outerHeight() - $('header').outerHeight())) { if($( window ).width() > 767) $('#intro').css('margin-bottom', $(affixElement).outerHeight() + 'px'); $(affixElement).css('position', 'fixed'); $(affixElement).css('top', $('header').outerHeight() + 'px'); } else { if ($(window).width() > 767) $('#intro').css('margin-bottom', ''); $(affixElement).css('position', ''); $(affixElement).css('top', ''); } }); //jQuery for page scrolling feature - requires jQuery Easing plugin $(function() { $('a.page-scroll').bind('click', function (event) { var $anchor = $(this); //alert("1"); //alert($(document).scrollTop()); //alert($($anchor.attr('href')).offset().top); //alert($('header').outerHeight()); //alert($(affixElement).outerHeight()); //alert($('#main-nav-div').outerHeight()); var scrollTo; //if ($(affixElement).outerHeight() != $('#main-nav-div').outerHeight()) //if the menu is in phone mode (hamburger), and the menu is fixed, the scroll has to subtract(add?) out the height of the uncollapsed menu if ($('#main-nav-div').attr('aria-expanded') == "true" && $('#navbar-main').css("position") === "fixed") scrollTo = $($anchor.attr('href')).offset().top - $('header').outerHeight() - $(affixElement).outerHeight() + $('#main-nav-div').outerHeight() + 3; else scrollTo = $($anchor.attr('href')).offset().top - $('header').outerHeight() - $(affixElement).outerHeight() + 3; $("#main-nav-div").collapse('hide'); //if ($(document).scrollTop() < ($(affixElement).offset().top - $('header').outerHeight())) //if ($(affixElement).offset().top > $('header').outerHeight()) // scrollTo = scrollTo - $(affixElement).outerHeight(); //alert(scrollTo); //alert($(document).scrollTop()); //alert($(affixElement).offset().top - $('header').outerHeight()); $('html, body').stop().animate({ scrollTop: scrollTo }, 1500, 'easeInOutExpo'); event.preventDefault(); }); //$('a.page-scroll-intro').bind('click', function (event) { // //alert("2"); // //alert($(document).scrollTop()); // var $anchor = $(this); // $('html, body').stop().animate({ // scrollTop: $($anchor.attr('href')).offset().top - 50 // }, 1500, 'easeInOutExpo'); // event.preventDefault(); //}); }); //this makes the menu snap to top after it scrolls to the top (adds .affix class to menu), so the condition is if scroll position is at the top minus the header's height. //$(affixElement).affix({ // offset: { // // Distance of between element and top page // top: function () { // return (this.top = $(affixElement).offset().top - $('header').outerHeight())// - $(affixElement).outerHeight()) // } // //, // //// when start #footer // //bottom: function () { // // return (this.bottom = $('#footer').outerHeight(true)) // //} // } //});