Reputation: 345
As it says in the Q, I want to make an element fixed if I scroll the page down more than 14px.
I tried the following but for some reason it is not working.
$(window).unbind('scroll').scroll(function () {
if ($('body').scrollTop > 140) {
$('div.top-logo-main').css('position', 'fixed');
} else {
$('div.top-logo-main').css('position', 'static');
}
});
Upvotes: 0
Views: 140
Reputation: 11693
Use scrollTop() as its functtion
$(window).unbind('scroll').scroll(function () {
if ($('body').scrollTop() > 140) {
$('div.top-logo-main').css('position', 'static');
} else {
$('div.top-logo-main').css('position', 'fixed');
}
});
demo http://jsfiddle.net/djgNG/
Its all right I got what you mean, check this new fiddle http://jsfiddle.net/djgNG/2/
Upvotes: 3
Reputation: 6809
scrollTop
is a function. Call it (note the parenthesis):
if ($('body').scrollTop() > 140) {
Upvotes: 1