我的代码包含 HTML、CSS 和 js 文件。虽然我可以接受 CSS 学习 JS,但我还是陷入了困境。输出中的绿色窗口似乎是滑动的,但实际上并没有。
我也在用 <script src="js/modernizr.custom.js"></script>
引用 js 页面但它没有发生所以即使我已经尝试了所有这些重新定位的东西但是我无法从 HTML 引用即使它不在 TAG 下的同一个 HTML 页面上工作
$( "#toggle" ).click(function() {
$(".menu").toggleClass("closed");
$(this).toggleClass("closed");
$(".content").toggleClass("closed");
$("#wrapper").toggleClass("closed")
});
* { font-family:courier; box-sizing:border-box; }
html, body { margin:0; padding:0; height:100%; min-height:100%; background-color:floralwhite }
.menu { width:250px; height:100%; position:fixed; background-color:seagreen; transition:all 1s; left:0; z-index:50; overflow-y:auto; padding-bottom:100px; }
.menu.closed { left:-250px; }
#toggle { background-color:seagreen; height:100%; min-height:100%; width:50px; position:fixed; top:0; bottom:0; left:0px; z-index:25; &:hover { cursor:pointer; } &.closed { left:0px; top:0; bottom:0; right:0; width:100%; height:100%; opacity:.3; } transition:all .7s ease; }
.menu ul { list-style-type:none; padding:0; margin:85px 0 0 40px; padding-right:40px; }
.menu ul li { color:floralwhite; font-size:20px; margin:0 0 5px 0; display:block; height:40px; line-height:40px; &:hover { background-color:lighten(seagreen, 10%); cursor:pointer; } padding-left:10px; transition:all .3s; }
<div id="toggle">
</div>
<div class="menu closed">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Logo</a></li>
<li>Stuff</li>
<li>Cooking</li>
<li>Games</li>
</ul>
</div>
最佳答案
您的 CSS 包含 SCSS 元素,例如
#toggle {
...
#toggle:hover {
cursor: pointer;
}
...
}
纯 CSS 中没有嵌套。将这些嵌套规则转换为普通 CSS(并将 jQuery 添加到代码片段)以使其工作。
一般来说,始终确保您的标记、样式和 javascript 代码没有语法错误。有很多工具可以做到这一点。
$("#toggle").click(function() {
$(".menu").toggleClass("closed");
$(this).toggleClass("closed");
$(".content").toggleClass("closed");
$("#wrapper").toggleClass("closed")
});
* {
font-family: courier;
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
min-height: 100%;
background-color: floralwhite
}
.menu {
width: 250px;
height: 100%;
position: fixed;
background-color: seagreen;
transition: all 1s;
left: 0;
z-index: 50;
overflow-y: auto;
padding-bottom: 100px;
}
.menu.closed {
left: -250px;
}
#toggle {
background-color: seagreen;
height: 100%;
min-height: 100%;
width: 50px;
position: fixed;
top: 0;
bottom: 0;
left: 0px;
z-index: 25;
transition: all .7s ease;
}
#toggle:hover {
cursor: pointer;
}
#toggle.closed {
left: 0px;
top: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
opacity: .3;
}
.menu ul {
list-style-type: none;
padding: 0;
margin: 85px 0 0 40px;
padding-right: 40px;
}
.menu ul li {
color: floralwhite;
font-size: 20px;
margin: 0 0 5px 0;
display: block;
height: 40px;
line-height: 40px;
padding-left: 10px;
transition: all .3s;
}
.menu ul li:hover {
background-color: lighten(seagreen, 10%);
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="toggle">
</div>
<div class="menu closed">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Logo</a></li>
<li>Stuff</li>
<li>Cooking</li>
<li>Games</li>
</ul>
</div>
关于javascript - 滑动菜单不滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46017904/