gpt4 book ai didi

javascript - 隐藏 div 的导航栏

转载 作者:行者123 更新时间:2023-12-01 05:23:33 28 4
gpt4 key购买 nike

我的导航栏隐藏了应该位于其上方的 div

不是我自己的完整复制品,但这是 fiddle

HTML:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Burger Corner</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/scrolling-nav.css" rel="stylesheet">
<link rel="icon" href="images/favicon.png" type="image/x-icon">

</head>
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
<!-- NAVBAR -->
<nav class="navbar navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- <a class="navbar-brand page-scroll" href="#page-top">Burger Corner</a>-->
<img src="images/logo.png" width="90" height="60">
</div>

<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right main-nav">
<li class="hidden"><a class="page-scroll" href="#page-top"></a></li>
<li><a class="page-scroll color_animation" href="#intro">Welcome</a></li>
<li><a class="page-scroll color_animation" href="#services">About us</a></li>
<li><a class="page-scroll color_animation" href="#reservation">Reservation</a></li>
<li><a class="page-scroll color_animation" href="#contact">Contact us</a></li>
<li><a id="login_lnk"class="page-scroll color_animation" href="#login" data-toggle="modal" >Login</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Intro Section -->
<section class="top-title">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Burger Corner</h1>
</div>
</div>
</div>
</section>

<section id="intro" class="intro-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Welcome section</h1>
</div>
</div>
</div>
</section>

<!-- About Section -->
<div id="wall_1" class="image"></div>
<section id="about" class="about-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>About Section</h1>
</div>
</div>
</div>
</section>

有问题的 div 和有效的 CSS:

.top_title{
font-family: 'Playball', cursive;
/* background-image: url(../images/intro.jpg) no-repeat center center;*/
background-size: cover;
width: 100%;
height: 100px;
background-color:#990000;
text-align:center;
padding-top: 150px;
}

.intro-section {
height: 100%;
padding-top: 150px;
text-align: center;
background: #fff;
z-index: 1;
}

导航栏的 CSS:

.color_animation {
text-decoration: none;
margin-right: -5px;
margin-left: -5px !important;
color: white !important;
-webkit-transition: color 0.3s ease-out;
-moz-transition: color 0.3s ease-in-out;
-o-transition: color 0.3s ease-in-out;
-ms-transition: color 0.3s ease-in-out;
transition: color 0.3s ease-in-out;
}
.color_animation:hover{
color: #990000 !important;
}

.main-nav a {
font-size: 20px;
font-weight: 700;
text-decoration: none;
color: #000;
display: block;
text-align: center;
padding: 2px 0;
transition: color 0.3s ease-in-out;
}

.main-nav {
padding: 0;
/*margin: auto 0 auto;*/
}

li{
color: white !important;
word-spacing: 5px !important;
}

额外的CSS:

body {
width: 100%;
height: 100%;
}

html {
width: 100%;
height: 100%;
}

@media(min-width:767px) {
.navbar {
padding: 20px 0;
-webkit-transition: background .5s ease-in-out,padding .5s ease-in-out;
-moz-transition: background .5s ease-in-out,padding .5s ease-in-out;
transition: background .5s ease-in-out,padding .5s ease-in-out;
}

.top-nav-collapse {
padding: 0;
}
}

我什至尝试使用 intro-section 类并修改它,更改其名称并添加一些代码,但它确实不起作用。navbar 隐藏了它,它没有有我告诉它的背景,甚至是高度

我将navbar设置为不可见只是为了测试,正如您所看到的,div位于navbar下方,橙色部分是我所说的我拿走它的css 并修改它。

最佳答案

我认为您的代码没有 CSS 解决方案。您可以通过删除或添加 navbar-fixed-top 类来检查滚动位置以使导航栏固定并返回静态,如下所示:

 $(window).scroll(function() {
if ($(window).scrollTop() > 50) {
$('.navbar').addClass('navbar-fixed-top');
}
if ($(window).scrollTop() < 51) {
$('.navbar').removeClass('navbar-fixed-top');
}
});

已更新 FIDDLE

关于javascript - 隐藏 div 的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41525542/

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