thanks in advance for any suggestions. I'm trying to build a site that uses a basic parallax scroll element. Basically, the header is positioned 60% from the top of the page. As the user scrolls, the content below the header catches up to the header and flows underneath it.
I can get all this to work perfectly, but I'd also like the header to stick to the top of the page when it gets up there. I've gotten it to sort of work, but when the header is stuck, it's very flashy/jumpy. I've seen other people with similar problems, and they seem to stem from switching the header position from static to fixed, but in my layout, the header is always fixed, so I'm a bit perplexed. Maybe the positioning I'm using seems a bit strange, but after much experimentation, this is the closest I could get it.
Here's a JSFiddle, and the code:
http://jsfiddle.net/kromoser/Lq7C6/11/
JQuery:
$(window).scroll(function() {
var scrolled = $(window).scrollTop();
if (scrolled > $('#header').offset().top) {
$('#header').css('top','-60%');
}
else {
$('#header').css('top',(0-(scrolled*0.6))+'px');
}
});
CSS:
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#header {
position: fixed;
top: 0;
margin-top: 60%;
z-index: 3;
background: #FFF;
width: 100%;
}
#content {
min-height: 100%;
position: relative;
top: 100%;
}
HTML:
<div id="header">This header should stick to top when scrolled.</div>
<div id="content">Content goes here</div>
Thanks for any help!