I'm trying to make a responsive Navigation Bar Menu in jQuery, but one problem is when you resize the window, click the menu button, then click it again, and then resize the window to full screen, the navigation bar will disappear. I'm not sure how to fix this.
Here is a JSFiddle: https://jsfiddle.net/tqu1edez/ I also posted the code here too.
HTML:
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel = "stylesheet" type ="text/css" href = "nav.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
</head>
<body>
<nav class = "navigationBar">
<img src = "https://i.imgur.com/nfbKl0W.png" class = "menuIcon">
<ul class = "linkBar">
<li><a href = "#">Home</a></li>
<li><a href = "#">Contact</a></li>
<li><a href = "#">About</a></li>
<li><a href = "#">Media</a></li>
<li><a href = "#">Miscellaneous</a></li>
</ul>
</nav>
<script>
$('.menuIcon').on('click', function() {
$('nav ul').fadeToggle('slow');
});
</script>
</body>
</html>
CSS:
@import url('https://fonts.googleapis.com/css?family=Asap');
body
{
background-color: #598392;
margin: 0;
padding: 0;
font-family: 'Asap', sans-serif;
}
.menuIcon
{
display:none;
}
.navigationBar
{
background-color: #124559;
width:100%;
overflow:hidden;
}
.navigationBar li
{
padding:20px;
display: inline;
list-style-type:none;
}
a
{
color: #EFF6E0;
text-decoration: none;
}
a:hover
{
color: #AEC3B0;
}
nav ul
{
padding: 20px;
margin: 0;
}
.show
{
display:block;
transition: fadeIn 2s
}
@media only screen and (max-width: 768px)
{
.menuIcon
{
display:block;
}
.navigationBar li
{
display:block;
padding: 0px;
text-align: center;
}
nav ul
{
display:none;
}
}