滚动功能jquery
问题描述:
我有一个固定的标题。 我想改变的不透明度时,我向下滚动,恢复时,我向上滚动(在页面顶部) 我写下这个简单的脚本不透明度:滚动功能jquery
$(window).scroll(function() {
if(scrollY == 0){
$("#header").animate({
opacity: 1
}, 1000);
}
if(scrollY > 0){
$("#header").animate({
opacity: 0.5
}, 1000);
}
});
居然头采取的不透明度时,我滚动但当我滚动页面的顶部,他永远不会回到不透明:1。 为什么?
答
这可能是更好的方法。在将不透明度设置为.5
之前,它会检查#header
是否已生成动画。
此外,它将#header
缓存在scroll
处理程序之外的变量中。性能更好。
var $header = $('#header');
$(window).scroll(function() {
if(scrollY <= 0){
$header.animate({
opacity: 1
}, 1000);
}
if(scrollY > 0 && $header.is(':not(:animated)')){
$header.animate({
opacity: .5
}, 1000);
}
});
谢谢,它运作良好! – andrea 2010-05-27 13:21:34
@andrea - 很高兴帮助。 @ karim79 - 感谢+:o) – user113716 2010-05-27 13:32:07