萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> 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;  }  }  });   
copyright © 萬盛學電腦網 all rights reserved