I've implemented a sticky navbar that changes color on scroll, but the transition feels abrupt. Here's the code snippet:
// jshint esversion: 6
window.onscroll = function() { myFunction(); };
let navbar = document.getElementsByClassName("navigation")[0];
let sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
}
/* CSS styles */
....(CSS content)
<!DOCTYPE html>
<html lang="en">
....(HTML content)
</html>
I'm looking to add a smoother transition effect when the navbar sticks to the top using CSS transitions. Any suggestions or help would be greatly appreciated.