jquery如何实现锚点链接之间的平滑滚动
更新时间:2013年12月02日 17:38:52 作者:
实现锚点链接之间的平滑滚动的方法有很多,在接下来的文章中为大家介绍下,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;
}
}
});
相关文章
ASP.NET jQuery 实例6 (实现CheckBoxList成员全选或全取消)
ASP.NET jQuery 实例6 (实现CheckBoxList成员全选或全取消) ,需要的朋友可以参考下。2012-01-01
jquery scrollTop方法根据滚动像素显示隐藏顶部导航条
使用jquery的scrollTop方法监视页面垂直滚动像素,并根据像素隐藏或者显示顶部的导航条,具体实现代码如下,感兴趣的朋友可以参考下哈2013-05-05


最新评论