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

JavaScript

How to create overlapping scroll effect

How do i create an effect where the top half disappears as you scroll down like this: http://lokeshdhakar.com/projects/lightbox2/

1 Answer

You don't need JS for this. Taking a look at the source code, it looks like this can be done with two divs. A backdrop to hold the stuff you want in the header, and a content div to hold everything that will scroll over it.

.backdrop {
    position: fixed;
    z-index: 5;
    width: 100%;
    height: 100%;
    background-color: #F5F5F5;
}

.content {
    position: absolute;
    z-index: 10; /* Important! Must be higher than .backdrop's z-index. */
    width: 100%;
    border-top: 1px solid #E8E8E8;
    background-color: #FFF;
    top: 28rem; /* How much space to give the backdrop section */
}