Hi there,
you can use the Javascript MutationObserver to watch the navigation for an ID change and when it does tack on your body class.
Try this in a wp_footer
hook:
<script>
const stickyNav = document.querySelector('#site-navigation')
const mutateOptions = {
attributes: true
}
function callback(mutationList, observer) {
mutationList.forEach(function(mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'id') {
// handle class change
if (mutation.target.id == 'sticky-navigation') {
document.body.classList.add("nav-is-sticky")
} else {
document.body.classList.remove("nav-is-sticky")
}
}
})
}
const observer = new MutationObserver(callback)
observer.observe(stickyNav, mutateOptions)
</script>