I'm attempting to dynamically change the logo in my header based on how far I've scrolled down the page. While I have experimented with libraries like Midnight.js, I specifically need to display an entirely different logo when scrolling, not just alter the image's color. Although I tried implementing a solution like the one below, it doesn't seem to be working as intended.
<script>
window.onscroll = function() {myFunction()};
function myFunction() {
if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
var source= "images/whitelogo.png";
} else {
var source= "images/blklogo.png";
}
}
</script>
<h1 id="myP" ><a href="index.html" ><img alt="logo" src=source; style="height:2.8em" /></a></h1>
Any assistance provided will be greatly appreciated!