I'm trying to add a drop shadow to my site's fixed navigation bar when it reaches a certain section. Can anyone explain why this isn't working?
In my .CSS,
.whiteDropShadow {
-moz-box-shadow: 0 0 10px #FFFFFF;
-webkit-box-shadow: 0 0 10px #FFFFFF;
-o-box-shadow: 0 0 10px #FFFFFF;
box-shadow: 0 0 10px #FFFFFF;
}
In my .JS,
$(function() {
// Initial top offset from ABOUT section
var topOffset = $('#about').offset().top;
// FUNCTION: adds class to #navLinks when vertical distance from the top is larger than the initial top offset.
var editNavBar = function(){
var verticalDistance = $(window).scrollTop(); // Current vertical distance from the top
if (verticalDistance > topOffset) {
$('#navLinks').addClass('.whiteDropShadow');
} else {
$('#navLinks').removeClass('.whiteDropShadow');
}
};
// Run upon scrolling
$(window).scroll(function() {
editNavBar();
});
});
I have it working here. I just logged out your values to make sure you could scroll far enough for the conditional to be hit. Also added
#navLinksto yourwhiteDropShadowselector.I'd double check your able to scroll long enough on your page to make your conditional truthy.
http://jsfiddle.net/y2zu5cwn/