将非哈希链接添加到单页导航

时间:2017-04-22 19:30:56

标签: jquery hash hyperlink navigation onepage-scroll

这可能是一个愚蠢的问题,但我已经尝试了几件事,似乎无法让它发挥作用。我希望简单地将硬/外部链接添加到我当前的导航中,该导航基于this.hash(目前它是一个单页网站)。代码如下:

jQuery(".tabs-btn ul li a, .navbar-nav li a, .navbar-brand").click(function (event) {
    event.preventDefault();
    //calculate destination place
    var dest = 0;
    if ($(this.hash).offset().top > $(document).height() - $(window).height()) {
        dest = $(document).height() - $(window).height();
    } else {
        dest = $(this.hash).offset().top;
    }
    //go to destination
    jQuery('html,body').animate({scrollTop: dest}, 1000, 'swing');
});

需要更改/添加什么才能使此代码接受外部链接而不仅仅是哈希链接?谢谢!

0 个答案:

没有答案