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

来源:互联网 发布:淘宝用户名大全 编辑:程序博客网 时间:2024/05/21 11:35
$('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; } } });

原创粉丝点击