Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
Hi there, I am trying to make my webpage template more interactive with some Javascript. One of the things I am trying to do is change the nav bar background once scrolled past the main hero image. I currently have some javascript created but nothing seems to be working. I would love to know if you can lead me to some resources or can help me out.
Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
Yeah I can confirm that the navigation has two classes with commas (typos) on the end: "main-nav," and "blue,".
So removing the comma ton make it "main-nav" will get it to work; however, it will make the styling from the smaller "main-nav" apply to the whole thing - which includes being hidden on mobile.
A complete solution would be to remove the "main-nav," and "blue," classes from the whole nav and then apply a different class like "main-nav-wrapper". Then change the jquery function to:
jQuery(document).ready(function($){
var topofDiv= $(".hero-image").offset().top;
var height= $(".hero-image").outerHeight();
$(window).scroll(function(){
if($(window).scrollTop()>(topofDiv+height)){
$(".main-nav-wrapper").addClass("blue")
}else
{
$(".main-nav-wrapper").removeClass("blue")
}
});
});
Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
I also noticed that your mobile navigation gets obstructed by your header. You can fix this by adding "z-index: 1000;" to the css of the mobile navigation (#mobile-nav)
Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
Thanks for figuring out the mobile navigation issue - almost forgot about that!
And I tried the code you suggested - not sure if it did anything. I'm noticing a syntax error in my inspect panel that might be relating to the javascript. Thoughts?
Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
Okay, that is getting somewhere! Maybe the class just has to be different since it's only around the links? (I want it to be the whole navigation bar where it's the dark blue).
Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
Okay, I see why. That small section is wrapped with the "main-nav" class, while the whole nav is wrapped with "main-nav," (with a comma on the end). Is this a typo in the template editor?
Trying to Change Nav Bar color when scrolling down the page after hero image.
SOLVE
Yeah I can confirm that the navigation has two classes with commas (typos) on the end: "main-nav," and "blue,".
So removing the comma ton make it "main-nav" will get it to work; however, it will make the styling from the smaller "main-nav" apply to the whole thing - which includes being hidden on mobile.
A complete solution would be to remove the "main-nav," and "blue," classes from the whole nav and then apply a different class like "main-nav-wrapper". Then change the jquery function to:
jQuery(document).ready(function($){
var topofDiv= $(".hero-image").offset().top;
var height= $(".hero-image").outerHeight();
$(window).scroll(function(){
if($(window).scrollTop()>(topofDiv+height)){
$(".main-nav-wrapper").addClass("blue")
}else
{
$(".main-nav-wrapper").removeClass("blue")
}
});
});