Skip to content

Instantly share code, notes, and snippets.

@ArtemSites
Last active February 22, 2024 10:04
Show Gist options
  • Save ArtemSites/7dcdb7186afe83c1ca6a7ac7ecc3ff97 to your computer and use it in GitHub Desktop.
Save ArtemSites/7dcdb7186afe83c1ca6a7ac7ecc3ff97 to your computer and use it in GitHub Desktop.
let infoTopFixed = false
window.addEventListener("scroll",function(e) {
if (infoTopFixed) {
let bodyOffsetY = document.body.getBoundingClientRect().y
let posY = (document.body.classList.contains('header-promo-visible')) ? 96 : 48
if (-1*bodyOffsetY <= posY) {
infoTop.classList.remove('fixed')
infoTopFixed = false
}
} else if (!infoTopFixed && infoTop.getBoundingClientRect().y <= 0) {
infoTop.classList.add('fixed')
infoTopFixed = true
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment