Nico Haemhouts

Nico Haemhouts Enterprise UI & Web Developer

Affix and stack elements on scroll.

A simple javascript to stack elements at the top of the screen when the user scrolls. It's kind of like the affix plugin in Twitter Bootstrap, except that you don't have to supply the offset-top yourself and elements are stacked under the top navigation bar.

Code and Demo

Because Codepen shows the demo in an iframe, the postion:fixed doesn't work on iOS. As a result, Twitter Bootstrap's navbar won't stick to the top of the screen. So, if you're on an iPhone or iPad you can check it out here in fullscreen.

See the Pen Affix and stack elements at the top of the screen on scroll. by Nico Haemhouts (@nicohaemhouts) on CodePen.