- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想这样做,当用户滚动时,较小 View 中展开的导航栏将消失。这是它的样子:
当用户滚动时,我希望它折叠起来。
https://jsfiddle.net/2pzx0fqy/
忽略损坏的图像,我怎样才能使导航栏消失?基本上,我现在切换导航栏的方式是使用最大高度和过渡。因此,当用户滚动时,我怎样才能使它折叠导航栏,同时用户可以再次单击它?
HTML:
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel = "stylesheet" type ="text/css" href = "nav.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<nav class = "navigationBar">
<img src = "https://i.imgur.com/nfbKl0W.png" class = "menuIcon">
<ul class = "linkBar">
<li><a href = "#"><i class="fa fa-home"></i> Home</a></li>
<li><a href = "#"><i class="fa fa-star" aria-hidden="true"></i> Skills</li>
<li><a href = "#"><i class="fa fa-envelope" aria-hidden="true"></i> Contact</a></li>
<li><a href = "#"><i class="fa fa-user" aria-hidden="true"></i> About</a></li>
<li><a href = "#"><i class="fa fa-briefcase" aria-hidden="true"></i> Services</a></li>
<li><a href = "#">Miscellaneous</a></li>
</ul>
</nav>
<section class = "title">
<img src = "me.jpg" class = "me">
<h1 class = "top-name"></h1>
<h2 class = "top-subtitle">Student - Web Developer - Tutor/Educator</h2>
</section>
<section class = "skills">
<h1 class = "head-title">Skills</h1>
<div class = "skill-icons">
<img src = "bigicons/java.png" id = "java">
<img src = "bigicons/c.png">
<img src = "bigicons/html.png">
<img src = "bigicons/js.png">
<img src = "bigicons/css.png">
<img src = "bigicons/git.png">
</div>
<div class = "modal" id = "modal">
<div class = "modal-content" id = "lol">
<span class="close">×</span>
<p>This is a Modal</p>
</div>
</div>
</section>
<section class = "about">
<h1 class = "head-title">About</h1>
<article class = "about-article">
</article>
</section>
<section class = "contact">
<article>
Interested in collaborating or just want to get to know me more? Lucky for you, there are several ways you can reach out to me.
</article>
<article>
</article>
</section>
<script>
$('.menuIcon').on('click', function() {
$('nav ul').toggleClass('show');
});
$(function() {
$(document).on("mousewheel", function() {
$('nav ul').toggleClass('hide');
});
});
var modal = document.getElementById('modal');
var jBtn = document.getElementById('java');
var span = document.getElementsByClassName("close")[0];
jBtn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function ()
{
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
CSS:
@import url('https://fonts.googleapis.com/css?family=Asap');
@import url('https://fonts.googleapis.com/css?family=Bitter|Dosis|Fira+Sans|Nunito|Oxygen');
body
{
background-color: #598392;
margin: 0;
padding: 0;
font-family: 'Bitter', 'Asap', sans-serif;
}
.menuIcon
{
padding:20px;
display:none;
cursor:pointer;
transition: transform: 0.5s;
}
.navigationBar
{
background-color: #2E86AB;
width:100%;
overflow:hidden;
position:fixed;
z-index: 1;
}
.title
{
overflow:hidden;
display: flex;
flex-direction: column;
background-color: #F7C174;
padding-top:100px;
align-items: center;
}
.top-name
{
font-size:75px;
position: relative;
top:-60px;
text-align: center;
}
.top-subtitle
{
text-align: center;
position: relative;
top:-80px;
}
.navigationBar li
{
padding:20px;
display: inline;
list-style-type:none;
font-size: 22px;
}
a
{
color: #EFF6E0;
text-decoration: none;
}
a:hover
{
color: #AEC3B0;
}
nav ul
{
padding: 20px;
margin: 0;
transition: max-height 1s;
}
.title h1
{
padding: 75px 0 0 20px;
}
.title article
{
padding: 20px;
}
.me
{
width:250px;
height:250px;
border-radius: 100%;
}
.skills
{
background-color: #FFEECF;
overflow: hidden;
height:auto;
padding-bottom: 50px;
}
.skill-icons
{
display:flex;
width:100%;
justify-content:space-around;
flex-direction: row;
flex-wrap: wrap;
height: auto;
}
.skill-icons > img
{
padding: 50px;
height:128px;
width:128px;
}
.head-title
{
font-size: 60px;
text-align: center;
}
.about
{
overflow: hidden;
background-color: #F7C174;
}
.about-article
{
padding: 50px;
}
.contact
{
background-color: #FFEECF
}
/* Modal Stuff */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.show
{
display:block;
}
@media only screen and (max-width: 768px)
{
.menuIcon
{
display:block;
}
.navigationBar li
{
display:block;
padding: 10px;
text-align: left;
margin-left: 30px;
font-size: 16px;
}
nav ul
{
max-height: 0;
padding: 0px;
}
.show
{
max-height: 250px;
}
.hide
{
max-height: 0px;
}
.title article
{
padding: 20px;
}
.skill-icons > img
{
padding: 20px;
height:30%;
width:30%;
}
}
/*
@media only screen and (min-width: 768px)
{
nav ul
{
display: block !important;
}
}
*/
最佳答案
将此代码添加到您的 javaScript 中:
当您向下滚动时,它会逐渐消失。当用户向上滚动时,它会淡入。
如果这不是您想要的,请告诉我。
编辑:根据发帖者的要求,我更新了 javaScript 以使其无论向上滚动到哪里,它都会淡入。
var mywindow = $(window);
var mypos = mywindow.scrollTop();
var up = false;
var newscroll;
mywindow.scroll(function () {
newscroll = mywindow.scrollTop();
if (newscroll > mypos && !up) {
$('.navigationBar').stop().fadeOut();
up = !up;
console.log(up);
} else if(newscroll < mypos && up) {
$('.navigationBar').stop().fadeIn();
up = !up;
}
mypos = newscroll;
});
@import url('https://fonts.googleapis.com/css?family=Asap');
@import url('https://fonts.googleapis.com/css?family=Bitter|Dosis|Fira+Sans|Nunito|Oxygen');
body
{
background-color: #598392;
margin: 0;
padding: 0;
font-family: 'Bitter', 'Asap', sans-serif;
}
.menuIcon
{
padding:20px;
display:none;
cursor:pointer;
transition: transform: 0.5s;
}
.navigationBar
{
background-color: #2E86AB;
width:100%;
overflow:hidden;
position:fixed;
z-index: 1;
}
.title
{
overflow:hidden;
display: flex;
flex-direction: column;
background-color: #F7C174;
padding-top:100px;
align-items: center;
}
.top-name
{
font-size:75px;
position: relative;
top:-60px;
text-align: center;
}
.top-subtitle
{
text-align: center;
position: relative;
top:-80px;
}
.navigationBar li
{
padding:20px;
display: inline;
list-style-type:none;
font-size: 22px;
}
a
{
color: #EFF6E0;
text-decoration: none;
}
a:hover
{
color: #AEC3B0;
}
nav ul
{
padding: 20px;
margin: 0;
transition: max-height 1s;
}
.title h1
{
padding: 75px 0 0 20px;
}
.title article
{
padding: 20px;
}
.me
{
width:250px;
height:250px;
border-radius: 100%;
}
.skills
{
background-color: #FFEECF;
overflow: hidden;
height:auto;
padding-bottom: 50px;
}
.skill-icons
{
display:flex;
width:100%;
justify-content:space-around;
flex-direction: row;
flex-wrap: wrap;
height: auto;
}
.skill-icons > img
{
padding: 50px;
height:128px;
width:128px;
}
.head-title
{
font-size: 60px;
text-align: center;
}
.about
{
overflow: hidden;
background-color: #F7C174;
}
.about-article
{
padding: 50px;
}
.contact
{
background-color: #FFEECF
}
/* Modal Stuff */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
.show
{
display:block;
}
@media only screen and (max-width: 768px)
{
.menuIcon
{
display:block;
}
.navigationBar li
{
display:block;
padding: 10px;
text-align: left;
margin-left: 30px;
font-size: 16px;
}
nav ul
{
max-height: 0;
padding: 0px;
}
.show
{
max-height: 250px;
}
.hide
{
max-height: 0px;
}
.title article
{
padding: 20px;
}
.skill-icons > img
{
padding: 20px;
height:30%;
width:30%;
}
}
/*
@media only screen and (min-width: 768px)
{
nav ul
{
display: block !important;
}
}
*/
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel = "stylesheet" type ="text/css" href = "nav.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<nav class = "navigationBar">
<img src = "https://i.imgur.com/nfbKl0W.png" class = "menuIcon">
<ul class = "linkBar">
<li><a href = "#"><i class="fa fa-home"></i> Home</a></li>
<li><a href = "#"><i class="fa fa-star" aria-hidden="true"></i> Skills</li>
<li><a href = "#"><i class="fa fa-envelope" aria-hidden="true"></i> Contact</a></li>
<li><a href = "#"><i class="fa fa-user" aria-hidden="true"></i> About</a></li>
<li><a href = "#"><i class="fa fa-briefcase" aria-hidden="true"></i> Services</a></li>
<li><a href = "#">Miscellaneous</a></li>
</ul>
</nav>
<section class = "title">
<img src = "me.jpg" class = "me">
<h1 class = "top-name"></h1>
<h2 class = "top-subtitle">Student - Web Developer - Tutor/Educator</h2>
</section>
<section class = "skills">
<h1 class = "head-title">Skills</h1>
<div class = "skill-icons">
<img src = "bigicons/java.png" id = "java">
<img src = "bigicons/c.png">
<img src = "bigicons/html.png">
<img src = "bigicons/js.png">
<img src = "bigicons/css.png">
<img src = "bigicons/git.png">
</div>
<div class = "modal" id = "modal">
<div class = "modal-content" id = "lol">
<span class="close">×</span>
<p>This is a Modal</p>
</div>
</div>
</section>
<section class = "about">
<h1 class = "head-title">About</h1>
</section>
<section class = "contact">
<article>
Interested in collaborating or just want to get to know me more? Lucky for you, there are several ways you can reach out to me.
</article>
<article>
</article>
</section>
<script>
$('.menuIcon').on('click', function() {
$('nav ul').toggleClass('show');
});
$(function() {
$(document).on("mousewheel", function() {
$('nav ul').toggleClass('hide');
});
});
var modal = document.getElementById('modal');
var jBtn = document.getElementById('java');
var span = document.getElementsByClassName("close")[0];
jBtn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function ()
{
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
关于javascript - 滚动时如何使导航栏消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48371860/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!