【发布时间】:2018-09-02 23:38:27
【问题描述】:
当我点击#navicon-1 元素时,我似乎无法让nav ul 向下滑动。
我在这个codepen 中使用了 SASS 和 PUG,下面是 编译的 版本:
$(document).ready(function(){
$('#nav-icon1').click(function(){
$(this).toggleClass('open');
});
});
nav {
width: 100%;
background: blue;
}
nav ul {
width: 80%;
margin: 0 auto;
text-align: center;
}
nav ul li {
display: inline-block;
padding: 40px;
transition: 0.5s;
}
nav ul li:hover {
background: black;
}
nav ul li a {
text-decoration: none;
color: white;
}
@media only screen and (min-width: 360px) and (max-width: 767px) {
#nav-icon1 {
right: 0;
width: 60px;
height: 45px;
position: absolute;
margin: 10px 10px;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transitions: 0.5s ease-in-out;
-moz-transitions: 0.5s ease-in-out;
-o-transform: 0.5s ease-in-out;
transform: 0.5s ease-in-out;
cursor: pointer;
}
#nav-icon1 span {
display: block;
position: absolute;
height: 9px;
width: 100%;
border-radius: 9px;
opacity: 1;
background: black;
left: 0;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transitions: 0.25s ease-in-out;
-moz-transitions: 0.25s ease-in-out;
-o-transitions: 0.25s ease-in-out;
transition: 0.25s ease-in-out;
}
#nav-icon1 span:nth-child(1) {
top: 0px;
}
#nav-icon1 span:nth-child(2) {
top: 18px;
}
#nav-icon1 span:nth-child(3) {
top: 18px;
}
#nav-icon1 span:nth-child(4) {
top: 36px;
}
#nav-icon1.open span:nth-child(1) {
top: 18px;
width: 0%;
left: 50%;
}
#nav-icon1.open span:nth-child(2) {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
#nav-icon1.open span:nth-child(3) {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
#nav-icon1.open span:nth-child(4) {
top: 18px;
width: 0%;
left: 50%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<nav>
<div id="nav-icon1"><span></span><span></span><span></span><span></span></div>
<ul>
<li><a href="#">Lorem</a></li>
<li><a href="#">Lorem</a></li>
<li><a href="#">Lorem</a></li>
<li><a href="#">Lorem</a></li>
</ul>
</nav>
【问题讨论】:
-
您将
.open类添加到#nav-icon1,并且您希望它影响不是#nav-icon1子级的UL?您需要定位要显示/隐藏的元素。也许向您希望定位的元素添加一些类会使代码/问题更清晰。 -
是的,我想在
#nav-icon1为open时显示nav。在目前的状态下,我希望它被隐藏,但我的代码对我来说太复杂了,我不知道自己在做什么了。
标签: jquery sass responsive-design pug