我是JQuery的新手,我确信答案是超级基本的。但如果有人能够指出我的方向是正确的,那就太好了。我只是希望我的标题的不透明度从0变为1,因为用户滚动超过400像素。救命? www.HULU.com就是一个很好的例子。
<code>
<script>
$(document).ready(function() {
$(window).scroll(function() {
if ($(this).scrollTop() > 400) {
$('.header').css("background", "#000");
} else {
$('.header').css("background", "transparent");
}
});
});
</script>
</code>
答案 0 :(得分:8)
试试这个:
HTML:
<div class="header">
<div id="background"></div>
<div id="labels">
labels here
</div>
</div>
<div class="content">
</div>
CSS:
.header{
width:100%;
height:100px;
position:fixed;
top:0px;
z-index:3;
}
body{
margin:0px;
}
.header #background, .header #labels
{
position:absolute;
top:0px;
width:100%;
height:100%;
}
.header #labels{
background-color:transperent;
}
.header #background{
background-color:yellow;
display:none;
}
.content{
width:100%;
height:5000px;
background-color:green;
}
JQuery的:
$(window).scroll(function() {
if ($(this).scrollTop() > 400) {
$( ".header #background" ).fadeIn();
} else {
console.log('there');
$( ".header #background" ).fadeOut();
}
});