Happy New Year!
I’m working on incorporating a bit of JS, but it’s not getting triggered, any pointers on what I might be doing incorrectly. I was following this example from W3School. I’m wondering if it is something with the call to the ‘window’ and the structure of blocs.
I’ve got multiple blocs with a div class of ‘content’ and one bloc with an element id of ‘navbar’.
Thanks!
<script>
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>