Simple Header and Footer Parallax Effect
I have been working on our Open Mapping site for our open data and open source apps, and I wanted to do a fancy-pants parallax effect on the front page so the content eats the header and reveals the footer as you scroll. This turned out to be some straight-forward CSS and didn’t involve any JavaScript scrolling action.
Let’s take your basic header->content->footer structure inside of a wrapper.
1 | <div class="wrapper-parallax"> |
The first thing you’ll need to do is set the position of the header and footer fixed to the top and bottom respectively with a z-index
of -1 to push it below the regular page content. And although I’m sure you are already CSS-normalizing, for the example we will specifically toss the body margin.
1 | body { |
Next we’ll give the content a minimum height to avoid having the footer lost in space in our example, a solid background color so it can eat stuff, and a z-index
of 1 so it’ll sit on top.
1 | .content { |
Now we set the wrapper margin off the top and bottom the same size as the header and footer.
1 | .wrapper-parallax { |
And that’s it - simple header and footer parallax effect without JavaScript.