I am trying to change a css style based on where on the page the viewer is. I have read through every similar thread on google and here and this code seems to be what I want, but it does not work. Any help would be greatly appreciated. Thanks.
Script I was modifying: http://jsfiddle.net/BKnzr/151/
and my testing page (non working): http://newmedia.academyart.edu/~02225904/portfolio/test.html
and the jquery that I am trying to use:
// cache the elements
var $container = $('#container');
var $nav = $('#a.nav');
var $home = $('#home');
var $about = $('#about');
var $work = $('#work');
var $contact = $('#contact');
// get the view area of #container
var top=$(window).scrollTop();
var bottom = top + $container.height();
// run code when #container is scrolled
$container.scroll(function() {
if ($home.offset().top < bottom) {
$nav.css({"color":"green","font-size":"20px"});
} else if ($about.offset().top < bottom) {
$nav.css({"color":"green","font-size":"20px"});
} else if ($work.offset().top < bottom) {
$nav.css({"color":"green","font-size":"20px"});
} else {
$nav.css({"color":"green","font-size":"20px"});
}
});
$for your variables. makes it confusing if it's a jQuery object or a mere variable.