0

ヘルプが必要です。1 ページ レイアウトの Web ページを作成していて、スクリプトへのスクロールがありますが、ナビゲーション バー クラスのボタンを押すと表示されるようにしたいです。私が意味したのは?

ボタンを押すたびにその位置までスクロールしますが、見たい htttp://mysite.com/#top

これは私が持っているものです

    $(function(){
$('a[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) {
            var targetOffset = $target.offset().top;
            $('html,body').animate({scrollTop: targetOffset - 100}, 800); /* Offest 100px because of the fixed nav manu */
            return false;
        }
    }
  });
});
4

1 に答える 1

0

質問の意味がよくわからないかもしれませんが、ハッシュ (#top) を表示したい場合はreturn false;、コードから削除してください。

于 2015-08-06T07:58:27.117 に答える