I've been struggling to figure out this code:
<script>
window.onload = function() {myFunction()};
window.onscroll = function() {myFunction()};
function myFunction() {
const top1 = document.getElementById("big-landing");
let y1=top1.scrollTop;
const top2 = document.getElementById("cbt-1");
let y2=top2.scrollTop;
const top3 = document.getElementById("cbt-2");
let y3=top3.scrollTop;
if ( document.documentElement.scrollTop >= y1 && document.documentElement.scrollTop < y2)) {
document.getElementById("logo").src = "/assets/logo-no-type-inv.svg";
$(".menu-circle").css("background-color", "black");
$(".menu-overlay a").css("color", "white");
if($(".dynamic-header-text").css("color") === "black")
$(".dynamic-header-text").css("color", "white");
else $(".dynamic-header-text").css("color", "black");
} else if (document.documentElement.scrollTop >= y2 && document.documentElement.scrollTop < y3){
document.getElementById("logo").src = "/assets/logo-no-type.svg";
$(".menu-circle").css("background-color", "#ffaa00");
$(".menu-overlay a").css("color", "black");
if($(".dynamic-header-text").css("color") === "white")
$(".dynamic-header-text").css("color", "black");
else $(".dynamic-header-text").css("color", "white");
} else if (document.documentElement.scrollTop >= y3) {
document.getElementById("logo").src = "/assets/logo-no-type-inv.svg";
$(".menu-circle").css("background-color", "black");
$(".menu-overlay a").css("color", "white");
if($(".dynamic-header-text").css("color") === "black")
$(".dynamic-header-text").css("color", "white");
else $(".dynamic-header-text").css("color", "black");
}
}
</script>
Struggling with making the fixed header and full screen menu change color dynamically based on scroll position. It only works when comparing "document.documentElement.scrollTop" against a set value like 500px. Need help for responsive design.