/* Code to make the breadcrumb sticky when scrolling up only */ // Select the breadcrumb var breadcrumbPanel = document.getElementsByClassName('sticky-breadcrumb-panel') // Define when the user is scrolling down let previousScrollPosition = 0; const ScrollingDown = () => { let goingDown = false; let scrollPosition = window.scrollY; if (scrollPosition > previousScrollPosition) { goingDown = true; } previousScrollPosition = scrollPosition; return goingDown; }; // Function that handles what happens when you scroll down const breadcrumbScrollBehaviour = () => { // If the user us scrolling down if (ScrollingDown()) { // Hide the breadcrumb breadcrumbPanel[0].style.top = '-' + breadcrumbPanel[0].offsetHeight + 'px' // Otherwise (when scrolling up), } else { // Reveal the breadcrumb breadcrumbPanel[0].style.top = '0' // Then, retrieve the current vertical scroll position var scrollPositionA = window.scrollY // Then, wait 2.5 seconds and setTimeout(function() { // Retrieve the vertical scroll position once again var scrollPositionB = window.scrollY // Check if user has not scrolled in 2.5 seconds if (scrollPositionA === scrollPositionB) { // If user has not scrolled, hide the breadcrumb once again breadcrumbPanel[0].style.top = '-' + breadcrumbPanel[0].offsetHeight + 'px' // Otherwise } else { // Do nothing return } }, 2500) } }; // Trigger breadcrumbScrollBehaviour function every time the user scrolls window.addEventListener('scroll', breadcrumbScrollBehaviour);