gpt4 book ai didi

javascript - 为什么汉堡包子菜单导航打不开?

转载 作者:行者123 更新时间:2023-11-28 00:36:12 26 4
gpt4 key购买 nike

相关代码如下,完整代码为here .导航代码遵循此笔:https://codepen.io/taniarascia/pen/dYvvYv所有样式/脚本/html 都是正确的。我不知道是什么导致服务下拉列表无法在移动 View 中下推以下 li 元素。当我第一次把它放在我的网站上时,下拉菜单起作用了,但在处理了一些看似无关的事情后,它不起作用了,我不知道此时发生了什么。检查器显示正在应用所有正确的样式,并且没有应用额外的样式。

HTML

<div class="main_nav">
<div class="navigation">
<div class="nav-container">
<div class="brand">
<a href="/"><img src="assets/images/logo.svg" style="height: 100%;"></a>
</div>
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
<a href="/">Home</a>
</li>
<li>
<a href="/#about">About</a>
</li>
<li>
<a href="#!">Services</a>
<ul class="nav-dropdown">
<li>
<a href="/web-design">Web Design</a>
</li>
<!--<li>-->
<!-- <a href="#!">Web Development</a>-->
<!--</li>-->
<!--<li>-->
<!-- <a href="#!">Graphic Design</a>-->
<!--</li>-->
</ul>
</li>
<li>
<a href="/portfolio">Portfolio</a>
</li>
<li>
<a href="/#contact">Contact</a>
</li>
<li>
<a href="/blog">Blog</a>
</li>
</ul>
</nav>
</div>
</div>
</div>

CSS

@charset "UTF-8";
.main_nav {
position: fixed;
top: 0px;
max-height: 70px;
z-index: 10;
width: 100vw;
/* padding-top: 17px; */
background: none;
-webkit-transition: all 0.3s;
transition: all 0.3s;
opacity: 0;
/* padding-bottom: 6px; */
left: 0;
right: 0;
height: 70px;
padding: 10px 4px;
box-sizing: border-box;
}

@media only screen and (max-width: 500px) {
.main_nav {
padding-top: 25px;
}
}

.sticky {
background-color: #ffffff;
opacity: 1;
top: 0px;
}

.navigation {
height: 50px;
background: #ffffff;
}

.brand {
position: absolute;
padding-left: 20px;
float: left;
height: 50px;
line-height: 70px;
text-transform: uppercase;
font-size: 1.4em;
/* width: 40%; */
}
.brand a,
.brand a:visited {
color: #5fc3e4;
text-decoration: none;
}

.nav-container {
max-width: 1000px;
margin: 0 auto;
}

nav {
float: right;
height: 50px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
background-color: white;
}
nav ul li {
float: left;
position: relative;
height: 50px;
line-height: 50px;
}
nav ul li a,
nav ul li a:visited {
display: block;
padding: 0 20px;
line-height: 50px;
background: #ffffff;
color: #5fc3e4;
text-decoration: none;
}
nav ul li a:hover,
nav ul li a:visited:hover {
color: #cfcfcf;
}
nav ul li a:not(:only-child):after,
nav ul li a:visited:not(:only-child):after {
padding-left: 4px;
content: ' ▾';
}
nav ul li ul li {
min-width: 190px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}

.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

/* Mobile navigation */
.nav-mobile {
display: none;
position: absolute;
top: 0;
right: 0;
background: #ffffff;
height: 70px;
width: 70px;
}

@media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}

nav {
width: 100%;
padding: 50px 0 15px;
}
nav ul {
display: none;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}

.nav-dropdown {
position: static;
}
}
@media screen and (min-width: 799px) {
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
}
#nav-toggle span,
#nav-toggle span:before,
#nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: #5fc3e4;
position: absolute;
display: block;
content: '';
transition: all 300ms ease-in-out;
}
#nav-toggle span:before {
top: -10px;
}
#nav-toggle span:after {
bottom: -10px;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}

JS

 (function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery

最佳答案

您在控制台中还有其他 js 错误。

例如:

pen.js:11 Uncaught ReferenceError: $ is not defined
at pen.js:11

这会阻止后面的代码执行。

一旦我清理干净(有 2 或 3 个),汉堡包就开始工作了: https://codepen.io/lennart_rikk/pen/ZVqJVZ

(注意!在 css 中我将主导航不透明度更改为 1,以查看菜单)

关于javascript - 为什么汉堡包子菜单导航打不开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54139648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com