I\'m trying to change the css of a div when scrolling. This is my code but unfortunately it won\'t work.
$(document).ready(function() {
$(window).scroll(f
Try this:
Here is working jsFiddle
$(document).ready(function() {
$(window).scroll(function() {
var scrollVal = $(this).scrollTop();
if ( scrollVal > 150) {
$('#subnav').css({'position':'fixed','top' :'0px'});
} else {
$('#subnav').css({'position':'static','top':'auto'});
}
});
});
Note: If you have just one value you can use else
, but if you have multiple values i suggest to not use else
, because it creates conflict, use else if
intead.