我想制作一个单页网站,其 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;
}
}
});
});`
任何人都可以帮助我放松部分吗?我希望滚动在靠近锚点时快速开始并减慢速度。
提前致谢。