var initLandingpage = function() { var heightLpNavbar = $('.m-landingpage_navigation').height(); var offsetLpNavbar = $('.m-landingpage_navigation').position().top; var headerHeight = 60; if ($('.o-header--lite').length) { headerHeight = 105; } // ## Sticky Navbar $('.landingpage_navigation-navbar').affix({ offset: { top: offsetLpNavbar } }); // ## Change Hashtag on scroll $('body').scrollspy({ target: '.landingpage_navigation-navbar', offset: heightLpNavbar + headerHeight }); $('body').on('activate.bs.scrollspy', function (event) { var curActiveLabel = $.trim($('.m-landingpage_navigation .navbar.lp-navbar .nav.navbar-nav li.active').eq(0).find('a').text()); var target = $("a.marker[href^='#']", event.target); if (target.length > 0) { $('.m-landingpage_navigation .navbar.lp-navbar .navbar-lp-active span').html(curActiveLabel); history.replaceState({}, "", target.attr("href")); } }); // ## Click on inpage navigation $('.m-landingpage_navigation .navbar-nav a.marker[href^="#"]').on('click', function (event) { event.preventDefault(); var section = $(this.hash); if (section.length) { $('html, body').animate({ scrollTop: section.offset().top - headerHeight - 20 }, 500); } // close mobile navigation if ($(window).width() < 991) { $('.m-landingpage_navigation .navbar.lp-navbar .navbar-toggle').trigger('click'); } }); // ## Jump to section on page load if there's a Hashtag if (location.hash) { var activated_link = $('.m-landingpage_navigation .navbar-nav a[href="' + location.hash + '"]'); // console.dir(activated_link); $(activated_link).trigger('click'); } }; $(function() { if ($('.m-landingpage_navigation').length && $('.m-landingpage_navigation').height) { if ($('#header + .o-videostage').length) { setTimeout(function(){ initLandingpage(); }, 2000); } else { initLandingpage(); } } });