Vertical Stacked Pages on Materialize

One-page with multiple stacked sections that reveal on scroll

Carol Skelly
WDstack
3 min readJun 14, 2016

--

The inspiration for this snippet I got when I discovered the beautiful portfolio work of Claudio Guglieri

I love the way the fixed page sections underneath reveal themselves as the current overlay page scrolls away.

After a little trial-and-error at Codeply, seemingly the best approach was a series of `position:absolute DIVs with a trailing dummy DIV at the end.

The last “dummy” DIV at the bottom allows the page to be scrolled. If you stack a bunch of full screen (100% width/height)`absolute` DIVs over each other the browser doesn’t need to scroll. The last DIV forces the browser to scroll, but it also must be full height. This last DIV also acts as a landing footer for the user to realize, “hey, I reached bottom!”.

I used Materialize for the colors and responsiveness, but you can use any framework (ie: Bootstrap, Foundation, etc..), or none for that matter since it only requires CSS and jQuery.

You’ll see the `min-height` instead of `height` is used on the BODY and `.page` class so that any give page can be taller than the viewport.

Try the demo.

HTML

CSS

JavaScript

This code is currently done in jQuery (which could also be implemented in pure JavaScript) and is used to..

  • Determine when the “current” (active) page has reached a viewport boundary.
  • Determine if the user is scrolling up or down.
  • Set the current page to “active”, the next page to “fixed”, and the prev page to “static”.

Here are the helper functions used to change the active page by switching CSS classes..

And, the helper functions used to determine when the position is at the bottom or top of a page section..

AngularJs is used on the demo site to fetch some random user data, and build the pages dynamically. Theoretically, it would be easy to switch the jQuery logic above as a Angular directive so I may investigate that later.

That’s it!

I hope you find this helpful, and let me know you’re comments & questions.

Try the demo, or grab the source code.

--

--

Carol Skelly
WDstack

S/W Engineer. Web developer. @Bootply @Codeply