【发布时间】:2013-10-09 22:19:30
【问题描述】:
您好,我正在尝试实现这种导航栏效果:http://kettlenyc.com/,这样当我向下滚动时,导航栏会跟随并动画到固定位置。我已经开始在这里编写代码,但无法让动画工作:http://theturning.co.uk/NOAH/
我的 Jquery 现在看起来像这样:
$(function() {
var bar = $('#topbar');
var top = bar.css('top');
$(window).scroll(function() {
if($(this).scrollTop() > 0) {
bar.stop().css({'position' : 'absolute'});
}
if($(this).scrollTop() > 600) {
bar.stop().animate({'top' : '0px'}, 100).css({'position' : 'fixed'});
} else {
bar.stop().animate({'top' : top}, 100);
}
});
});
还有 CSS:
#topbar {
background: url('../images/bg-topbar.png') left top;
position: absolute;
top: 0;
width: 100%;
height: 50px;
z-index: 999;
padding: 20px 0 20px 0;
}
任何帮助将不胜感激!谢谢
【问题讨论】:
-
尝试为不透明度设置动画,先将其设置为 0,然后再将其设置为 1。
-
您好,感谢您的回复。这将如何帮助将其从静态位置更改为像 Kettle 示例那样的固定位置?