一页主题平滑滚动 Bootstrap 导航 Link 在尝试打开其他页面时不起作用,但它对页面内的锚点有效

One page theme smooth-scrolling Bootstrap Navigation Link does not work when trying to open other pages, but it does work for anchors inside the page

我需要将我的一些导航栏按钮重定向回我的起始页。似乎平滑滚动编码需要菜单项指​​向主题标签锚点以使菜单项起作用并且这确实有效,但是当我尝试完全重定向到另一个页面时,没有任何反应。没有错误,也没有 div 覆盖按钮。

我在这里看到的一个解决方案涉及向滚动条代码添加一条语句,以禁用特定外部 link 标签的需要,但我不知道如何对此进行编码,我的模板代码是与线程中提到的不同。换句话说,只要按钮没有 class "ext-link",我就需要一个代码来声明执行常规操作 onclick。有关更具体的详细信息,请参阅下面的 link。 One page theme Bootstrap Navigation Link does not direct to another page, while it works for anchors inside the page

我不完全确定下面的代码是否正确,但看起来是这样。我将如何重写它以包含一个 "if click and not class=ext-link" 案例,以便我可以从我的站点根目录为我的导航栏启用外部 links?

jQuery('#scrollToContent').click(function(e){
    e.preventDefault();
    jQuery.scrollTo("#portfolio", 1000, { offset:-(jQuery('#header .top').height()), axis:'y' });
});

jQuery('.nav > li > a').click(function(e){
    e.preventDefault();
    jQuery.scrollTo(jQuery(this).attr('href'), 400, { offset:-(jQuery('#header .top').height()), axis:'y' });
})

jQuery(window).scroll( function() {
   //setHeaderBackground();
});

如果我做对了,你可以用这段代码修改第二个点击事件处理程序,它应该可以工作:

jQuery('.nav > li > a').click(function(e){
    var $this = jQuery(this);

    if (!$this.hasClass('ext-link')) {
        e.preventDefault();
        jQuery.scrollTo($this.attr('href'), 400, { offset:-(jQuery('#header .top').height()), axis:'y' });
    }
})

希望这对您有所帮助。 :)