定义锚点,点击a标签跳转到相应的版块,使页面滚动产生效果

 $('a.page-scroll').click(function(e) {
         if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
             var target = $(this.hash);
             console.log(target);
             target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
             if (target.length) {
                 $('html,body').animate({
                     scrollTop: target.offset().top - 40
                 }, 900);
                 return false;
             }
         }
     });

你可能感兴趣的:(jQuery)