var element = document.getElementById('navBar') window.addEventListener('scroll', function() {
element.getBoundingClientRect().top < 0 ? element.classList.add('stuck') : element.classList.remove('stuck');
});