Reputation: 5957
I am having trouble following this stackOverflow Q&A:
Fix object to top of browser window when scrolling
I have applied it to this this page
Why is my object not attaching to the top like it should and then being replaced properly when the page is scrolled back to the top?
My jQuery:
$(window).scroll(function () {
if ($(window).scrollTop() > 200) {
$('#contentNavigation').css('top', $(window).scrollTop());
}
}
);
Upvotes: 3
Views: 1921
Reputation: 1066
http://jsfiddle.net/mikelegacy/tXBHT/
Please re-review this. Here is what you want.
Upvotes: 4
Reputation: 1418
Edit: This is a much better method of solving the problem, use position fixed when necessary and leave your css alone.
Replace your javascript with this:
$(window).scroll(function () {
if ($(window).scrollTop() > 200) {
$('#contentNavigation').css('position', 'fixed').css('top','0px'); }
else {
$('#contentNavigation').css('position', 'relative').css('top','0px');
}});
Upvotes: 1