Your code has some errors
first your search selector must be an ID or Class then it must be "#search" or ". search"
second variable javascript does not have $ so the code should look like this
var w = $(window);
w.on("scroll", function(){
if( w.scrollTop() > 100 ) {
$('.busca').css("position", "fixed");
}
else{
$('.busca').css("position", "static");
}
});
EDIT
Maybe it works better this way by setting top:0 z-index one level above the others
var w = $(window);
w.on("scroll", function(){
if( w.scrollTop() > 100 ) {
$('.busca').css({"position":"fixed", "top":"0px","z-index":"1"});
}
else{
$('.busca').css({"position": "static"});
}
});
Is there an error in the console? Try to take the value of scrollTop and give a console and see the result...
– DiegoSantos
@Diegosantos includes the console.log in if and it came back right. console.log("Greater than 100");
– Felipe Viero Goulart
Pera, your element does not call search... Not missing a point before? or a hashtag? Type $('#search'). css("position", "Fixed"); ???
– DiegoSantos
Felipe think you can solve this only with CSS, unless you really want to use jQuery... If you want to put a simple example to do this with 5 CSS lines...
– hugocsl
@Diegosantos was that yes.
– Felipe Viero Goulart
@hugocsl can be yes
– Felipe Viero Goulart