window.addEventListener('resize', function() {
document.addEventListener('scroll', function() {
checkScrollHeight();
});
});
function checkScrollHeight() {
let stickyNavbar = document.getElementById('sticky-navbar');
let currentPosition = window.pageYOffset || document.documentElement.scrollTop;
let bannerHeight = document.getElementById('banner-height').offsetHeight || document.getElementById('banner-height').clientHeight;
if(currentPosition > bannerHeight) {
stickyNavbar.style.display = "block";
return;
} else {
stickyNavbar.style.display = "none";
}
}
Currently the function is working when the user resizes the page, but how can I write the code so the function will be called after reloading the page? The navbar should be displayed when it passes the specific height of the banner which will dynamically change based on the screen width.