I have created a hamburger menu specifically for smaller screens, and it is functioning properly on small screens. However, I am facing an issue where if the menu is not open before resizing the screen to a larger size, the menu does not show at all. When the screen is already larger and I refresh the page, the menu appears as expected. I am looking for a solution where the menu switches in real time when the screen reaches a media query breakpoint, displaying the full menu on larger screens.
Currently, I am using JQuery to handle the show/hide functionality of the menu.
https://jsfiddle.net/fabfivefebby/87rywxxv/
var $hamburger = $('<button id="hamburger">☰</button>');
$("header").append($hamburger);
// Toggle nav with icon
if ($("#hamburger").css("display") === "block") {
$("#nav_container").hide();
$hamburger.click(function(){
$("#nav_container").slideToggle("slow");
});
} else {
$("#nav_container").show();
}
Appreciate any help in advance!