【发布时间】:2011-04-04 12:04:11
【问题描述】:
我想制作一个单页网站,其 div(导航)位置固定,z-index 为 999。
我们的目标是让 div 保持在顶部并且所有其他内容都滚动。 我让它正常工作,但是我想通过缓动使它“更流畅”,但我尝试的一切都会使脚本停止工作。这是工作脚本:
$(document).ready(function(){
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000) ;
return false;
}
}
});
});`
任何人都可以帮我解决缓和部分吗?我希望滚动在靠近锚点时快速开始并放慢速度。
提前致谢。
【问题讨论】:
-
建议您编辑帖子以格式化 Javascript 代码,显示正常缩进。你所拥有的真的很难阅读。
标签: jquery scroll anchor easing