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

Design

Brandon Brigham
Brandon Brigham
3,716 Points

Changing sticky header position as you scroll down

Does anyone know how to adjust the positioning of a sticky or fixed header as the user scrolls down or scrolls down and then up?

4 Answers

Kevin Korte
Kevin Korte
28,149 Points

You'll need some sort of javascript to measure scroll position, and than do something based on that scroll position. It could be as simple as setting CSS classes at certain scroll positions an than let the CSS do something with that class.

Couple plugin options depending on what you want to do

Here's some options for doing things with scroll

http://www.webdesignerdepot.com/2013/12/25-free-scrolling-plugins-for-awesome-experiences/

Depends on what you're doing exactly, check out headroom.js. I've used before to shrink instead of hide the header. Fairly easy edit in css.

Hope this helps.

Brandon Brigham
Brandon Brigham
3,716 Points

Ali - If you go to my site that I'm working on http://andersoncoastalproperties.com/wp-admin username: andersoncoastal password: Anderson1905!

You can see that my header when scrolled at the top has a gap there (intentionally) my client wants that gap to disappear as the user scrolls down.. any ideas

Thans

You can definitely use headroom.js for your header. Instead of collapsing it move it up by those 40px. The nice thing is that headroom uses css for the transitions, so change it to move up a bit instead of hiding it completely.

It will look something like this:

.headroom--pinned {
    transform: translateY(0%);
}
.headroom--unpinned {
    transform: translateY(-40px);
}