//*** Sticky subnav *** //toggle .sticky class on main element based on scroll position function scrollFunction() { let a = document.querySelector("#main"); let masthead = document.querySelector(".ghf-masthead"); let masthead_height = masthead.offsetHeight; let scrollpos = window.scrollY; //once the button reaches top of viewport, stick it to top of viewport scrollpos >= masthead_height ? ((a.classList.add("sticky"))) : ((a.classList.remove("sticky"))); } //check document for subnav bar. If element exists, run the scrollFunction() function checkForElement () { let doc = document.querySelector("#stickSubNav"); if (doc != null) { $(function () { (window.onscroll = function () { scrollFunction(); }); }) } } checkForElement();