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