Javascript-滚动效果干扰链接

Javascript-滚动效果干扰链接,javascript,scroll,hyperlink,anchor,Javascript,Scroll,Hyperlink,Anchor,$('body a')。单击(函数(e){ e、 预防默认值(); var goTo=$(this.attr('href').replace('#',''); $(“html,body”).animate({ scrollTop:$('a[name=“”+goTo+'“]').offset().top },1100); window.location.hash=“#”+goTo; });这是因为e.preventDefault(); 它阻止链接工作,并将其设置为正文中的所有a标记 尝试使用其他脚

$('body a')。单击(函数(e){
e、 预防默认值();
var goTo=$(this.attr('href').replace('#','');
$(“html,body”).animate({
scrollTop:$('a[name=“”+goTo+'“]').offset().top
},1100);
window.location.hash=“#”+goTo;

});这是因为e.preventDefault(); 它阻止链接工作,并将其设置为正文中的所有a标记

尝试使用其他脚本

尝试:

   $('a[href*=#]:not([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) {
             $('html,body').animate({
                 scrollTop: target.offset().top
            }, 1100);
            return false;
        }
    } 
});