I have a Navaigation bar that i want to get fixed at the top only when the user scrolls the page to about 100px.
Which is the best way to achieve this?
http://play.mink7.com/sophiance/
Working DEMO here...http://jsfiddle.net/eFCK3/1/
<div id="header-small">Header</div>
<div>
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
</div>
#header-small{
display:none;background:red;padding:2%;position:fixed;top:0px;width:960%;
}
$JQUERY
$(window).scroll(function() {
if ($(this).scrollTop()>100) {
$('#header-small').fadeIn();
} else {
$('#header-small').fadeOut();
}
});
$(document).scroll(function () {
var y = $(this).scrollTop();
if (y > 100) {
//when page scrolls past 100px
} else {
//when page within 100px
}
});
hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With