我对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>
试试这个:
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();
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句