I’m new to CSS and HTML here and I’m trying to learn how to make something become absolutely positioned once you scroll by it on the page.
Here’s an example of what I mean: http://fab.com/help/ (you don’t need an account to scroll). When you scroll down, the black menu bar at the top disappears and the white menu bar with “How can we help you” becomes absolutely positioned.
I created a an example with a similar menu system,
but I don’t know where to start to make it become absolutely positioned once it’s scrolled by, thanks a lot for any insights!
See this jsFiddle: http://jsfiddle.net/jkdbP/2/
You can use jQuery’s
.offset().topto get the Y-position of your menu, andwindow.pageYOffset(ordocument.body.scrollTopfor old IE compatibility) to get the page’s scroll offset. You can then handle thewindow‘sscrollevent.