gpt4 book ai didi

javascript - 我的响应式导航栏不工作

转载 作者:行者123 更新时间:2023-11-28 02:06:54 30 4
gpt4 key购买 nike

好吧,所以当我尝试使下拉响应式导航栏但它不起作用时,如果有人可以帮助我,那就太好了:)

关于我的问题的更多信息。

所以当我按下这个按钮时菜单应该打开 picture of navbar

通常当我改变 header nav ul height 为 0 它关闭它但是当我将它更改为 auto 时;它打开菜单但不会关闭它所以我试图制作脚本,当您单击该图片时它会把它变成自动;但我似乎没有工作。所以我的问题是我无法打开或关闭它。

fa-bars 是来自 awesomefont 的图片,只是为了说明这一点。

这里是一些代码。

$(document).ready(function() {
$(".fa-bars").on("click", function() {
$("header nav ul").toggleClass("open");
});
});
/* MOBILES */

@media screen and (max-width: 480px){
#logo {
width: 80px;
margin-left: 30px;
margin-top: 15px;
}
header nav {
margin: 0;
float: none;
}
.fa-bars {
font-size: 24px;
display: inline-block;
width: 100%;
cursor: pointer;
text-align: right;
float: right;
margin: 13px 35px 0 0;
}
.fa-bars:hover {
opacity: 0.5;
}
header nav ul {
height: 0;
overflow: hidden;
margin: 0;
padding: 0;
width: 100%;
}
header nav ul.open {
height: auto;
}
header nav ul li {
width: 100%;
padding: 5px 0;
margin: 0;
font-size: 17px;
border-top: 1px solid #dddddd;
}

header nav ul li:hover {
background-color: #eeeeee;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script defer src="js/fontawesome.js"></script>
<title>SeQaFin</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:500" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">

</head>

<body>

<!-- Header -->
<header>
<div id="logo">
<a href="#">
<img src="img/logo.png" alt="Logo">
</a>
</div>

<!-- NavBar -->
<nav id="main-nav">
<i class="fas fa-bars"></i>
<ul>
<a href="#Kotisivu"><li>Etusivu</li></a></li>
<a href="#Tietoa"><li>Tieto</li></a>
<a href="#Liity"><li>Liity</li></a>
</ul>
</nav>
</header>

<!-- Etusivu -->
<section id="Kotisivu">
<h3 id="seqatext">DOwn</h3>
<a href="#Tietoa">
<img src="img/down.png" alt="Down">
</a>
</section>

<!-- Tietoa -->
<section id="Tietoa">
<h3>Tietoa</h3>
<hr>
<img src="img/avatar.png" alt="Avatar">
<h4></h4>
<p>
</p>

<h4></h4>
<p>
</p>

<h4></h4>
<p>
</p>

<h4></h4>
<p>
</p>
<br><br><br><br><br>
</section>

<!-- Liity -->
<section id="Liity">
<h3>Liity</h3>
<hr>
<h4>Ohjeet</h4>
<p>Ohjeet Tähän!</p>

<form>
<input class="input_text" type="email" tabindex="1" placeholder="Sähköposti"><br>
<input class="input_text" type="text" tabindex="2" placeholder="Otsikko"><br>
<textarea class="input_text" tabindex="3" placeholder="Viesti"></textarea><br>
<input class="button" type="submit">
</form>
</section>

<footer>
<p>
</p>
</footer>
<script src="js/jquery.js"></script>
<script src="js/mobile.js"></script>
</body>
</html>

最佳答案

您还没有加载您的脚本文件。

尝试使用我在此处所做的更正。

$(document).ready(function() {
$('.fa-bars').on('click', function() {
$('header nav ul').toggleClass('open');
});
});
@media screen and (max-width: 480px) {


#logo {
width: 80px;
margin-left: 30px;
margin-top: 15px;
}
}

header nav {
margin: 0;
float: none;
}

.fa-bars {
font-size: 24px;
display: inline-block;
width: 100%;
cursor: pointer;
text-align: right;
float: right;
margin: 13px 35px 0 0;
}

.fa-bars:hover {
opacity: 0.5;
}

header nav ul {
height: 0;
overflow: hidden;
margin: 0;
padding: 0;
width: 100%;
}

header nav ul.open {
height: auto;
}

header nav ul li {
width: 100%;
padding: 5px 0;
margin: 0;
font-size: 17px;
border-top: 1px solid #dddddd;
}

header nav ul li:hover {
background-color: #eeeeee;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script defer src="js/fontawesome.js"></script>
<title>SeQaFin</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:500" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">

</head>

<body>

<!-- Header -->
<header>
<div id="logo">
<a href="#">
<img src="img/logo.png" alt="Logo">
</a>
</div>

<!-- NavBar -->
<nav id="main-nav">
<i class="fas fa-bars"></i>
<ul>
<a href="#Kotisivu"><li>Etusivu</li></a></li>
<a href="#Tietoa"><li>Tieto</li></a>
<a href="#Liity"><li>Liity</li></a>
</ul>
</nav>
</header>

<!-- Etusivu -->
<section id="Kotisivu">
<h3 id="seqatext">DOwn</h3>
<a href="#Tietoa">
<img src="img/down.png" alt="Down">
</a>
</section>

<!-- Tietoa -->
<section id="Tietoa">
<h3>Tietoa</h3>
<hr>
<img src="img/avatar.png" alt="Avatar">
<h4></h4>
<p>
</p>

<h4></h4>
<p>
</p>

<h4></h4>
<p>
</p>

<h4></h4>
<p>
</p>
<br><br><br><br><br>
</section>

<!-- Liity -->
<section id="Liity">
<h3>Liity</h3>
<hr>
<h4>Ohjeet</h4>
<p>Ohjeet Tähän!</p>

<form>
<input class="input_text" type="email" tabindex="1" placeholder="Sähköposti"><br>
<input class="input_text" type="text" tabindex="2" placeholder="Otsikko"><br>
<textarea class="input_text" tabindex="3" placeholder="Viesti"></textarea><br>
<input class="button" type="submit">
</form>
</section>

<footer>
<p>
</p>
</footer>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/index.js"></script>
</body>
</html>

关于javascript - 我的响应式导航栏不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48969290/

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