There is a code. Whether prompt implementation is correct?
The point is that there is a website header that has two classes with different css styles. When scrolling down, it changes its styles, and if it is raised to the top of the page, it gets the original values.
The question is: is the code correctly implemented (does the code work)? Just want to know the opinion.
window.onscroll = function() { document.querySelector('#header'); var el = document.documentElement.scrollTop; if (el > 1) { document.querySelector('#header').classList.add("sticky"); } else { document.querySelector('#header').classList.remove("sticky"); } };