$(document).ready(function() {
$(".logo").click(function() {
$("#list").slideToggle(400);
});
$(window).resize(function() {
if ($(window).width() < 767) {
$("#list").slideUp(0);
} else {
$("#list").slideDown(0);
}
});
});
* {
padding: 0px;
margin: 0px;
}
#wholeNav {
height: 580px;
top: 0;
background-color: rgba(0, 0, 0, 0.8); /* BACKGROUND OPACITY */
margin: 0;
padding: 0;
}
#wholeNav::after {
content: "";
display: block;
position: absolute;
top: 0;
background-size: cover;
background-attachment: fixed;
background-position: center;
background-image: url(background.jpg); /* WHOLE BACKGROUND */
height: 580px;
width: 100%;
z-index: -2;
}
#wholeNav img[src="ham.png"] {
height: 100px;
display: none;
}
#navBar {
background-color: red;
max-width: 1200px;
margin: auto;
position: relative;
height: 100px;
width: 100%;
z-index: 10;
}
#list {
float: right;
width: 70%;
position: relative;
max-height: 100px;
margin: 0;
padding: 0;
background-color: green;
}
#list li {
float: right;
list-style-type: none;
display: inline;
margin-right: 10%;
font-size: 20px;
line-height: 100px;
padding: 0;
text-transform: uppercase;
}
li a {
text-decoration: none;
color: black;
}
a:hover { /* COLOR LETTER WEB VERSION */
color: yellow;
transition: 0.2s;
}
#navBar img[src="logo.png"] {
height: 100%;
margin: 0;
padding: 0;
}
@media screen and (max-width: 768px) {
#wholeNav {
margin-top: 0;
height: 500px;
}
#wholeNav::after {
height: 500px;
}
#wholeNav img[src="ham.png"] {
display: block;
height: 16px;
width: 22px;
padding: 14px 0;
margin-left: 6%;
}
#navBar {
position: fixed;
top: 0;
height: 44px;
margin-top: 0;
}
#list {
margin: 0;
width: 100%;
max-height: 218px;
overflow: hidden;
z-index: 2;
}
#list li {
display: block;
float: none;
width: 88%;
border-bottom: 1px solid rgba(0, 0, 0, 0.6);
font-size: 18px;
margin-left: 6%;
line-height: 40px;
text-transform: none;
}
a:hover { /* COLOR LETTER MOBILES VERSION */
color: yellow;
transition: 0.2s;
}
#navBar ul li:last-child {
border-bottom: 0px solid green;
}
<div id="navBar">
<img class="logo" src="ham.png">
<img src="logo.png">
<ul id="list">
<li> <a href="#"> Kop1 </a> </li>
<li> <a href="#"> Kop2 </a> </li>
<li> <a href="#"> Kop3 </a> </li>
<li> <a href="#"> Kop4 </a> </li>
<li> <a href="#"> Kop5 </a> </li>
</ul>
</div>
我正在使用导航栏。当我点击.logo-class(一个汉堡包图标)时,菜单必须向下滑动。 #list
是菜单。当我再次按下它时,菜单必须向上滑动。因此我使用slideToggle()
。当页面加载时,#list需要高度为0.但是现在该函数不起作用。有没有办法将高度设置为自动?我使用resize()因为我的网站有移动版和网络版。
当页面加载时,如果body.width为&lt;页面加载,则不得出现绿色部分(#list)。 768px。这是移动版本。