Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Alex Chow
4,521 PointsNavigation Link Behavior
Hi there,
I like to create one page sites because I like the aesthetic and the simplicity of them. On them, I use a fixed navigation that sits at the top the page when the user scrolls. I currently have hover and focus css properties added to them so the user knows which section they are currently visiting. To illustrate, when the user clicks on the Videos link on the nav, the link will turn to yellow and a border-bottom will be added to it. However, when the user scrolls away from the section say to the About Us portion, the nav will still show the active Videos link and not change which can cause confusion for the users. How can I resolve this? Is there some javascript or css I can use to enhance this experience?
Thank you.
1 Answer
Steven Parker
243,318 PointsOne way would be to use the onscroll event in JavaScript to check the page position after each scroll move and then apply the highlighting appropriately. How do you apply the highlighting now on a click?
I believe this functionality is also found in some popular front-end frameworks, in case you would consider using one of them.
Alex Chow
4,521 PointsAlex Chow
4,521 PointsI'll give this a try. Thank you.