I have a scroll function set up so when the window scrolls beyond 50px, the .header-wrap div animates from a height of 140px to 70px, ideally what should happen then is when you scroll back less than 50px from the top, the .header-wrap div should animate back from 70px to 140px but this function doesn't seem to be working as it should:
jsFiddle: http://jsfiddle.net/ub8Rb/
HTML:
<div class="header-wrap">hello</div>
<div class="scroll"></div>
CSS:
.header-wrap {
position: fixed;
width: 100%;
height: 140px;
top: 0;
left: 0;
text-align: center;
background-color: #999;
z-index: 9999;
}
.scroll {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 4000px;
}
jQuery:
$(document).scroll(function () {
if (window.scrollY > 50) {
$(".header-wrap").animate({
height: "70px"
}, 500);
} else {
$(".header-wrap").animate({
height: "140px"
}, 500);
}
});
This function doesn't seem to be working as I've described above, and not animating the height of the div dependant on how far the window has scrolled. Any suggestions are greatly appreciated!