(function () { 'use strict'; window.utils = window.utils || {}; window.utils.stickynav = function (nav) { var ticking = false; init(); function init() { window.setTimeout(function () { nav.classList.add('navbar--animated'); }, 200); checkScroll(); addListener(); } // checks scroll direction and shows/hides navbar accordingly function checkScroll() { var sticky = window.scrollY > 0; sticky = sticky && window.innerHeight < (document.scrollingElement.scrollHeight - 100); nav.classList.toggle('navbar--sticky', sticky); ticking = false; } function addListener() { window.addEventListener('scroll', function (e) { if (!ticking) { window.requestAnimationFrame(checkScroll); ticking = true; } }, false); } } })(); document.addEventListener('DOMContentLoaded', function () { utils.stickynav(document.querySelector('.js-sticky-navbar')); });