【发布时间】:2015-02-27 17:03:47
【问题描述】:
我有一张封面照片,它使用 jscript 以任何分辨率拉伸整个窗口。当您向下滚动时,封面会上升并显示内容。我试图让导航栏在封面照片完全向上滚动后淡入,然后在页面的其余部分保持导航栏静态,除非您向上滚动到封面照片,这将使导航栏淡出。不幸的是,如果我固定导航栏的位置,它根本不会显示。请帮忙。
HTML
<body>
<div id="container">
<div id="header">
</div>
<div id="navbar">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">About</a></li>
</ul>
</div>
</div>
</body>
CSS
html, body{
height:100%;
margin:0;
background:#F9F9F9;
/*This is to cut off the white border around the webpage*/
}
#container {
position: relative;
max-width: 2048px;
margin: 0px auto;
width: 100%;
height:100%;
}
#header {
background: url('../images/cover6.jpg') no-repeat;
background-size:cover;
height: 100%;
margin:0px auto;
width:100%;
}
#navbar ul{
list-style-type: none;
margin: 0;
padding: 0;
}
JSS
<script>
$(window).resize(function() {
$("#container").height($(window).height());
});
</script>
<script>
(function ($) {
$(document).ready(function(){
// hide .navbar first
$("#navbar").hide();
// fade in .navbar
$(function () {
$(window).scroll(function () {
// set distance user needs to scroll before we fadeIn navbar
if ($(this).scrollTop() > 1000) {
$('#navbar').fadeIn();
} else {
$('#navbar').fadeOut();
}
});
});
});
}(jQuery));
</script>
【问题讨论】:
标签: javascript jquery html css nav