A member asked:
Do you have any tutorials that will help me to make the site header stick to the top of the page and reduce the vertical padding upon scrolling, just like at: www.studiopress.com?
I have written about this in the past here: Shrinking Fixed Header in Genesis similar to that in Centric Pro.
In this tutorial I share a simplified version (esp. CSS) of the same.
Summary of the solution:
- When the user scrolls down, header gets a CSS class of
shrink
and when the user scrolls all the way to the top, this class is removed. - When the header has shrink class on, we remove its padding and use CSS transition property for smooth animation.
- Taking the standard case of Primary Navigation appearing below the header, we shall use JS (on load and resize) to automatically calculate the height of the fixed header and push the Primary Nav down by that many pixels using top margin.
While the tutorial has been written for Genesis Sample child theme it should work with minor adjustments in any Genesis child theme.
Step 1
Create a file named say, global.js in child theme's js
directory (create if not existing) having the following:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
[…] on February 11, 2016: Click here for a newer tutorial on this […]
And fix the menu so that it stays on the screen?
(NEVER satisfied!)
Updated the tutorial. See Addendum 1.
You are such a showoff! 😉
+ 1 for Larry, I think that is one of the major benefits of the solution.
BR
Hans
This is awesome! I’ve been wanting to do this for a while but just haven’t found a great tutorial. I’ve also added the .shrink class to my .title-area and my .nav-primary and applied the transitions and sizing your had on .site-header (and bit more) so I could have it all move around when the user scrolls down. Thanks so much!
You could wrap all those elements in a div and toggle the shrink class on it.
Great idea. Thanks!
Hi Sridhar,
How would I modify the JS to apply this ONLY if the window size is > 800px? This would allow me to apply separate menu actions for mobile screens < 800px.
Thanks!
Try these:
global.js: http://pastebin.com/raw/gbrQADBy
style.css: http://pastebin.com/raw/cqNv4xWB
I hooked in a rev slider (‘genesis_after_header’)
which is now at the top and behind the header, is there a fix fir this so that is right belowthe main nav?
https://camdenccc.com/
Can you give me the correct/updated URL where the problem can be seen?