Mastering Scroll Events (and Overcoming Resistance) ‎ ‎Day 10 of the JavaScript Challenge! 🚀 ‎ ‎Honestly, I almost didn't post today. I’m currently coding on an HP Stream with a cracked screen that is bleeding "ink" down the display. Between the hardware issues and the end-of-year fatigue, the temptation to quit was high. ‎ ‎But I remembered that code doesn't care if your screen is perfect; it only cares if your logic is sound. So, I pushed the editor to the bottom half of the screen and got to work. ‎ ‎Today, I built a ScrollSpy Landing Page. The goal was seamless navigation on both desktop and mobile. ‎ ‎✨ Key Features: ‎ ‎Sticky Navbar: Used window.pageYOffset to detect when the user scrolls past the header, triggering a CSS class to lock the navbar to the top. ‎ ‎Auto-Closing Mobile Menu: A common UX bug in mobile menus is that they stay open after you click a link. I fixed this by looping through all navigation links (querySelectorAll) and forcing the menu to close (classList.remove) whenever a link is clicked. ‎ ‎Back-to-Top Button: A dynamic button that only appears after the user has scrolled down 500px. ‎ ‎💻 Code Snippet: ‎ ‎JavaScript ‎ ‎// Auto-close menu on link click ‎scrollLinks.forEach((link) => { ‎ link.addEventListener("click", () => { ‎ linksContainer.classList.remove("show-links"); ‎ }); ‎}); ‎These small UX details make a huge difference in how a site feels. It wasn't easy to focus today, but showing up when it's hard is part of the job. ‎ ‎On to Day 11! 💪 ‎ ‎#JavaScript #100DaysOfCode #WebDesign #Frontend #Resilience #BuildingInPublic

To view or add a comment, sign in

Explore content categories