I'm trying to achieve a similar effect to the way the iOS Chromes navigation bar scrolls and hides, the comes back into view when scrolling up.
This JSfiddle is where I am so far.
var pos = $(window).scrollTop(),
header = $("header");
$(window).scroll(function () {
var newPos = $(this).scrollTop();
if (newPos > pos) { //down
header.css('top', -(newPos) + 'px');
if (pos > 40) {
header.css('top', '-40px');
}
} else { //up
header.css('top', '0');
}
pos = newPos;
$(".last span").html(pos);
$(".new span").html(newPos);
});
So the header scrolls up as you scroll down, but I can't work out how to scroll it back into view in the way I want. Tried using animate() which gave me a scroll in and out, but the animation wasn't smooth. I' want the header to move at the same speed as as the scroll, any ideas?