3

Web サイトでスムーズ スクロールと scrollspy を使用しているときに問題が発生します。ナビゲーション メニューのリンクをクリックすると、適切なセクションに移動します。このセクションにはタブがあります。タブの 1 つをクリックすると、スクロールバーが上下に移動します。

これが私のフィドルです

JS が起動しない理由がわかりません。誰か助けてくれませんか?

サンプル scrollspy コード:

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