I'm looking to create a dynamic hamburger menu that changes color based on different sections of the page. I've experimented with a few approaches, but encountered some issues - the first attempt only works when scrolling down, and the second attempt only affects the first two sections.
<div class="nav">
<svg class="burger" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="32px" id="Layer_1" style="enable-background:new 0 0 32 32;" version="1.1" viewBox="0 0 32 32" width="32px" xml:space="preserve">
<defs>
....
});
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
....
});
JS attempt 1 ( codepen- https://codepen.io/tarunpatnayak/pen/rNYQpwL)
const mSections = document.querySelectorAll("section");
....
});
JS attempt 2 (codepen - https://codepen.io/tarunpatnayak/pen/JjOeMJJ )
const mSections = document.querySelectorAll("section");
....
});
JS attempt 3 (jQuery)(codepen - https://codepen.io/tarunpatnayak/pen/VwrVrba )
var dOffset = $("[data-id = dark]").offset();
....
});