JQuery锚点链接平滑滚动效果

Web前端评论2.3K阅读模式

页面平滑滚动锚点代码:

  1. $(function(){
  2.     $('a[href*=#],area[href*=#]').click(function() {
  3.         if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
  4.             var $target = $(this.hash);
  5.             $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
  6.             if ($target.length) {
  7.                 var targetOffset = $target.offset().top;
  8.                 $('html,body').animate({
  9.                     scrollTop: targetOffset
  10.                 },
  11.                 1000);
  12.                 return false;
  13.             }
  14.         }
  15.     });
  16. })

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
  • JQuery
  • Javascript
  • Web前端
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证