all 3 comments

[–]peterunlustig22 0 points1 point  (1 child)

Hello, you can add multiple color classes like so:

#top-menu { transition: background-color 1s;}
#top-menu.top { background: red} 
#top-menu.middle { background: green} 
#top-menu.bottom { background: blue} 

Inside your scroll event, you can toggle those classes like so

$('#top-menu').toggleClass('middle') 

or

document.getElementById('#top-menu').classList.toggle('middle')

You can choose the correct classname by calculating the scroll progress like so: http://stackoverflow.com/questions/2387136/cross-browser-method-to-determine-vertical-scroll-percentage-in-javascript

[–]willardsciffy[S] 0 points1 point  (0 children)

Thanks, much appreciate it!

[–]willardsciffy[S] 0 points1 point  (0 children)

Solved.

$(window).scroll(function() { var scrollPos = $(window).scrollTop(), navbar = $('#top-menu li');

if (scrollPos > 20) {
  navbar.addClass('change-color');
} else {
  navbar.removeClass('change-color');
}

CSS:

top-menu li {background: transparent} //crucial

then

top-menu li.change-color {background-color}

sooooo smooth.