jquery 滚动,无法轻松工作
我想制作一个一页网站,其中的 div(导航)位置固定,z 索引为 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;
}
}
});
});`
任何人都可以帮助我处理缓动部分吗?我希望滚动快速开始,并在靠近锚点时减慢速度。
提前致谢。
I want to make a one page website with a div (navigation) with fixed position and z-index on 999.
The goal is to make the div stay on top and all the other content scroll.
I got this working properly, however i want to make it "more smooth" with easing, but everything i try makes the script stop working. This is the working script:
$(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;
}
}
});
});`
Can anyone help me with the easing part? I want the scrolling to start fast and slowing down when it is near the anchor.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
替换
为
确保您已包含 jQuery UI 核心和 jQuery Effects 核心。
replace
with
Make sure you have included jQuery UI core and jQuery Effects core.