24. 解决链接锚点的生硬问题
$(‘.nav .btn[href*=#],.icon2,.icon3‘).click(function() { if (location.pathname.replace(/^\//, ‘‘) == this.pathname.replace(/^\//, ‘‘) && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $(‘[id=‘ + this.hash.slice(1) + ‘]‘); if ($target.length) { var targetOffset = $target.offset().top; $(‘html,body‘).animate({ scrollTop: targetOffset }, 1000); return false; } } })
原文:http://www.cnblogs.com/duowen/p/5266298.html