I need help creating a dynamic menu that automatically adjusts in size as the user scrolls down. I found a script online and added it to my HTML file like this:
<script type="text/javascript">
$(function() {
var header = $(".large");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 50) {
header.removeClass('large').addClass("small");
} else {
header.removeClass("small").addClass('large');
}
});
});
</script>
In the HTML body, I set the header tag with the default class "large" and left it empty to test the script's behavior.
In the CSS, I styled the header class based on the characteristics of other divs on the page:
header.large{position:fixed; width:100%; height:20%; background-color:#00BFFF; top:0px; left:0; z-index:1;}
header.small{position:fixed; width:100%; height:7%; background-color:#000000; top:0px; left:0; z-index:1;}
Even after changing the color of the small class to verify the script's activation, it still doesn't work. Can anyone provide assistance? Thank you.