我对 JQuery 很陌生,我确信答案是非常基本的。但如果有人能指出我正确的方向,那就太好了。我只是希望当用户滚动超过 400 像素时,标题的不透明度从 0 更改为 1。帮助? 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>
最佳答案
试试这个:
Example: http://jsfiddle.net/SEH5M/
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();
}
});
关于jquery - 滚动时更改标题的不透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18441360/