Create a CSS class with the color you want and apply the effects you want. Then you have to measure the Scroll and decide from what value to apply that class.
In native Javascript this would be like this:
(function () {
var menu = document.getElementById('menu'); // colocar em cache
window.addEventListener('scroll', function () {
if (window.scrollY > 0) menu.classList.add('menuFixo'); // > 0 ou outro valor desejado
else menu.classList.remove('menuFixo');
});
})();
CSS
.menuFixo {
position: fixed;
top: 0px;
background-color: #ccf;
}
The reason to use (function () { ... })();
is because this way we can cache the element menu
, without exporting to global space, and saving resources once the event scroll
is fired many times.