/** * File back-to-top.js. * * Handles back to top button functionality. */ ( function() { const brevityBackToTopButton = document.getElementById( 'back-to-top' ); // Return early if button doesn't exist. if ( ! brevityBackToTopButton ) { return; } // Show/hide button based on scroll position function brevityToggleBackToTop() { if ( window.pageYOffset > 300 ) { brevityBackToTopButton.style.display = 'flex'; } else { brevityBackToTopButton.style.display = 'none'; } } // Scroll to top when button is clicked brevityBackToTopButton.addEventListener( 'click', function( e ) { e.preventDefault(); window.scrollTo( { top: 0, behavior: 'smooth', } ); } ); // Listen for scroll events window.addEventListener( 'scroll', brevityToggleBackToTop ); // Check initial scroll position brevityToggleBackToTop(); }() );