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

JavaScript Using jQuery Plugins Add a Sticky Navigation Bar The Plugin Challenge Solution

Harry Woodford
Harry Woodford
1,865 Points

Sticky nav, adding in the ACTIVE effect whilst scrolling

how do i make each <a> know it should be active depending where I've scrolled to on the page? I'm guessing some how a class is meant to be added like class="active". Any advise and help please :)

Please include your code, or a snapshot of your workspace and I'll do my best to help you.

1 Answer

Not sure if this is what you're asking, but using sticky's className option lets you change the class name of the wrapper element it creates around whatever you call the sticky function on (default is is-sticky). So you could call it like so:

$(".work").sticky(
  {
    topSpacing: 64,
    className: 'active'
  }
);

And the HTML would look like this:

<div id="undefined-sticky-wrapper" class="sticky-wrapper active" style="height: 23px;">
  <h5 class="work" style="width: 1264px; position: fixed; top: 64px;">Want us to work on your project? <a href="mailto:help@teamtreehouse.com">Email us</a></h5>
</div>