I would like my active tab to change colour when user scroll pass 1000px and return to original color when it's <1000px.
I've tried the CSS below which works and changes the background on active tab permanently.
.navbar-default .navbar-nav > .active{
background: #111;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background: #111;
}
Also tried combining the CSS above and a scroll function, but I don't think I'm targeting the active div right... How can I best target this active tab class in a scroll function? Or is there a better alternative to this method?
JsFiddle : https://jsfiddle.net/Lczsjz3y/7/
Any help would be appreciated :)
From your fiddle, it looks like you just need to add a listener to the scroll event, because as you have it now, it just pulls the
scrollTop()
value on load. So, something similar to this:Hope this helps.
It's not perfect and not the best solution, but I've tried playing around with what I know and manage to get what I wanted. https://jsfiddle.net/y791ur1x/3/
Still look forward to a proper clean solution though!! ^^
This will work:
Fiddle: https://jsfiddle.net/Lczsjz3y/21/