Reputation: 69
I want to change position fixed/relative of a div on scrolling down/up
working fine locally but not working on server
$(window).scroll(function(){
if($(window).scrollTop()>100)
{
$("#searchBar").css({
'position':'fixed',
'top':'0px',
'left':$("#wrapper").offset().left+1,
'width':$("#wrapper").width()
});
}
if($(window).scrollTop()<=100)
{
$("#searchBar").css({
'position':'relative',
'left':'0px'
});
}
});
Upvotes: 2
Views: 4106
Reputation: 21
Server uses different id for elements. So try getting the id from the server with this.
Your $("#searchBar")
should be $("[id$=searchBar]")
, and $("#wrapper")
should be $("[id$=wrapper]")
.
This worked for me perfectly.
Upvotes: 2