[英]Navigation bar disappearing below mobile screen width
I created a responsive navbar but here it's the problem,when i go into mobile width and open and close navbar ,and then i resize to the normal width,the navbar isn't there anymore and i have to refresh to make it show up again. 我创建了一个响应式导航栏,但这是问题所在,当我进入移动宽度并打开和关闭导航栏时,然后我将尺寸调整为正常宽度时,导航栏不再存在,我必须刷新以使其再次显示。 I used jQuery to toggle a class that animates between display:block and display:none and when i open and close the navbar then i resize to full width i think it remains to display:none.
我使用jQuery切换了一个在display:block和display:none之间进行动画处理的类,当我打开和关闭导航栏时,我将其尺寸调整为全宽,我认为它将保持为display:none。 How can i fix this ?
我怎样才能解决这个问题 ?
Here is the code : 这是代码:
HTML: HTML:
<header>
<div class="menu-trigger">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
<nav id="index-nav">
<ul>
<li><a id="active" href="index.html">HOME</a></li>
<li><a href="collection.html">COLLEZIONI</a></li>
<li><a href="events.html">EVENTI</a></li>
<li><a href="contact.php">CONTATTACI</a></li>
<li><a href="about.html">ABOUT</a></li>
<li><a href="colaborations.html">COLLABORAZIONI</a></li>
</ul>
</nav>
</header>
CSS: CSS:
#index-nav{
background-color: rgba(0, 0, 0, 0.2);
width:100%;
text-align:center;
position:absolute;
display:block;
}
#index-nav ul {
margin:0;
font-size:13px;
font-style:italic;
overflow: hidden;
}
#index-nav ul li{
list-style:none;
display:inline-flex;
padding:10px 4%;
}
@media (max-width:980px) {
.showing {
display: block;
}
#index-nav{
background-color:none;
background : #FFF;
display: none;
border-bottom: 0;
position:relative;
}
#index-nav ul li a{
color:black;
}
}
jQuery: jQuery的:
$(document).ready(function () {
$('.menu-trigger').on('click', function () {
$("#index-nav").slideToggle(400, function () {
$(this).toggleClass('showing').css('display',' ');
});
});
});
You've got a typo there - you should remove the space when setting the display to '': 您在这里输入错误-将显示设置为”时应删除空格:
Instead of .css('display',' ');
代替
.css('display',' ');
use .css('display', '');
使用
.css('display', '');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.