滚动更改标题的不透明度?

我是JQuery的新手,我确信答案是超级基本的。 但如果有人能够指出我的方向是正确的,那就太好了。 我只是希望我的标题的不透明度从0变为1,因为用户滚动超过400像素。 救命? www.HULU.com就是一个很好的例子。

  $(document).ready(function() { $(window).scroll(function() { if ($(this).scrollTop() > 400) { $('.header').css("background", "#000"); } else { $('.header').css("background", "transparent"); } }); });   

试试这个:

示例: http : //jsfiddle.net/SEH5M/

HTML:

 
labels here

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(); } });