html5中文学习网

您的位置: 首页 > 网站及特效实例 > javascript特效 » 正文

jquery如何实现锚点链接之间的平滑滚动_jquery_

[ ] 已经帮助:人解决问题
复制代码 代码如下:

$('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
},
500);
return false;
}
}
});
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助