3

当我在我的网站上使用平滑滚动和 scrollspy 时遇到问题。当我单击导航菜单链接时,我将被定向到相应的部分。在本节中,我有标签。当我单击其中一个选项卡时,滚动条会上下移动。

这是我的小提琴

不知道为什么我的 JS 没有触发。有人可以帮忙吗?

示例滚动间谍代码:

var $body = $(document.body); var navHeight = $('.navbar').outerHeight(true) + 80;
$body.scrollspy({
    target: '#leftCol',
    offset: navHeight
});

示例滚动代码:

$('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 - 120
            }, 1000);
            return false;
         }
     }
});
4

0 回答 0