gpt4 book ai didi

javascript - 使用 vanilla JavaScript 向下滚动时隐藏菜单,向上滚动时显示菜单

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

我有一个导航菜单。这个菜单,我用 Bootstrap 构建了它,我希望它在向下滚动时隐藏,在向上滚动时显示。我仅通过使用普通 JavaScript 来满足它的要求。

这是我的 HTML 代码:

<nav class="navbar navbar-default navbar-fixed-top  custom-header" >
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Menu</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<a class="navbar-brand" href="" style="color:#FFF">
<img src="img/header-logo.png" alt="Happy Tour" />
</a>
</div>

<!-- This section contains all link buttons in the header -->
<div class="collapse navbar-collapse pull-right mybtn" id="bs-example-navbar-collapse-1" style="margin-top:9px;">
<button class="btn btn-primary btn-md"><i class="glyphicon glyphicon-bookmark"></i> Destinations</button>
<button class="btn btn-success btn-md"><i class="glyphicon glyphicon-th"></i> Tour Package</button>
<button class="btn btn-danger btn-md"><i class="glyphicon glyphicon-file"></i> Book Ticket</button>
<button class="btn btn-info btn-md"><i class="glyphicon glyphicon-search"></i> Find Hotel</button>
<button class="btn btn-success btn-md"><i class="glyphicon glyphicon-user"></i> Register</button>
<button class="btn btn-primary btn-md"><i class="glyphicon glyphicon-fire"></i> Login</button>
</div>
</div>
</nav>

这是一个CSS:

.custom-header{
padding: 0;
height: 120px;
line-height: 120px;
background: url(../img/top_head_bg.jpg) repeat-x;
border:none;
}

最佳答案

就像本文建议的那样 Auto-Hide Sticky Header (我还使用这 4 个词立即在 Google 中找到了解决方案)您可以将您的标题设置为固定

.header {
width: 100%;
height: 7.5em;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
}

然后对滚动使用react,用 JS 更改 top 属性。

祝你好运

关于javascript - 使用 vanilla JavaScript 向下滚动时隐藏菜单,向上滚动时显示菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31698162/

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