.menu.fixed {
position: fixed;
top: 0;
}
(function() {
var menu = document.querySelector('.menu'),
menuIsFixed = false,
menuMaxTop = 400;
window.addEventListener('scroll', function() {
if(this.pageYOffset >= menuMaxTop != menuIsFixed) {
menuIsFixed = !menuIsFixed;
menu.classList[menuIsFixed ? 'add' : 'remove']('fixed');
}
});
})();