in advance for any suggestions. I am trying to create a site that uses the basic parallax scroll element. Basically, the title is 60% of the top of the page. When the user scrolls, the content under the heading reaches the heading and flows under it.
I can make it all work fine, but I would also like the title to go to the top of the page when it gets up there. I got a job, but when the heading is stuck, it is very flashy / nervous. I saw other people with similar problems, and they seem to be related to switching the position of the title from static to fixed, but in my layout the title is always fixed, so I'm a little puzzled. Perhaps the positioning I use seems a little strange, but after much experimentation, this is the closest I could get.
Here's the JSFiddle and 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!
jquery html css
Kevin
source share