mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-13 16:26:50 +00:00
36 lines
968 B
JavaScript
36 lines
968 B
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
const $body = document.body
|
|
const $headerAnchor = document.getElementById('header-anchor')
|
|
|
|
// Topbar
|
|
const topbarClass = 'topbar'
|
|
const topbarAppearClass = 'topbar--appear'
|
|
const addTopbar = () => {
|
|
$body.classList.add(topbarClass)
|
|
window.setTimeout(() => {
|
|
$body.classList.add(topbarAppearClass)
|
|
}, 25)
|
|
}
|
|
const removeTopbar = () => {
|
|
$body.classList.remove(topbarClass)
|
|
$body.classList.remove(topbarAppearClass)
|
|
}
|
|
|
|
if (
|
|
"IntersectionObserver" in window &&
|
|
"IntersectionObserverEntry" in window &&
|
|
"intersectionRatio" in window.IntersectionObserverEntry.prototype
|
|
) {
|
|
const headerObserver = new IntersectionObserver(entries => {
|
|
const { boundingClientRect: { y, height } } = entries[0]
|
|
if (Math.abs(y) > height) {
|
|
addTopbar()
|
|
} else {
|
|
removeTopbar()
|
|
}
|
|
})
|
|
|
|
headerObserver.observe($headerAnchor)
|
|
}
|
|
})
|