我需要将一些导航栏按钮重定向回我的起始页。似乎平滑滚动编码需要菜单项定向到主题标签 anchor 才能使菜单项发挥作用,这确实有效,但是当我尝试完全重定向到另一个页面时,什么也没有发生。没有错误,也没有 div 覆盖按钮。
我在这里看到的一个解决方案涉及向滚动条代码添加一条语句,以禁用特定外部链接对主题标签的需求,但我不知道如何对此进行编码,并且我的模板的代码与中提到的代码不同线。换句话说,我需要一个代码来声明在单击时执行常规操作,只要按钮没有“ext-link”类。请参阅下面的链接了解更多具体细节。 One page theme Bootstrap Navigation Link does not direct to another page, while it works for anchors inside the page
我不完全确定下面的代码是正确的,但看起来是这样。我如何重写它以包含“if click 而不是 class=ext-link”的情况,以便我可以从我的网站根目录为我的导航栏启用外部链接?
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' });
}
})
希望这有帮助。 :)
关于javascript - 单页主题平滑滚动 Bootstrap 导航链接在尝试打开其他页面时不起作用,但它确实适用于页面内的 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43809397/