2

scrollTo プラグインを使用して、いくつかの見出しにスクロールしています。ブラウザウィンドウの高さによって決まる小さな増分でのみ上にスクロールするという問題。私が使用しているIDを認識していないようです。

ここをクリックしてページを表示するには、ページの一番下までスクロールして、2 本の指で項目を選択する必要があります。上記の動作を確認するには、手動で下にスクロールして右側のリンクをクリックする必要があります (少し複雑で申し訳ありません)。

4

3 に答える 3

2

私はこの小さなスニペットをスコーリングに使用します

    ///  <summary>
    ///     Scrolls the page to a single matched element.
    ///     Limitations: The document can only scroll a maximum of it's height. If an element is at the bottom of a page with nothing
    ///     below it then it cannot move that element to the top of the page as nothing exists to fill the space.
    ///  </summary>
    ///  <param name="target" type="String">
    ///     The element to scroll to
    ///  </param>
    ///  <param name="padding" type="Integer">
    ///     The padding to add to the scrolling destination. Negative values reduce the scrolling distance.
    ///  </param>
    ///  <param name="speed" type="Integer">
    ///     The the speed at which to perform the animation. Positive integers only.
    ///  </param>
    function scrollTo(target, padding, speed) {

        // Define our variables.
        var target_offset, target_top;

        // Fix our value to add the selector.
        if (target.indexOf("#") == -1) {
            target = "#" + target;
        }

        // Get the top offset of the target anchor and add any necessarry padding.
        target_offset = $(target).offset();
        target_top = target_offset.top + padding;

        // Scroll to that anchor by setting the body to scroll to the anchor top.
        $("html").animate({ scrollTop: target_top }, speed);
    }
于 2010-10-20T13:47:40.023 に答える
2

これにはプラグインを使用する必要はありません。

以下のコードを試してください -

   $('html').animate({
    scrollTop: $('#id where you want to scroll').offset().top
    }, 2000);
于 2010-10-20T13:28:23.213 に答える
0

お二方ともご回答ありがとうございます。問題は、名前タグの親 div を CSS で非表示にし、JS で表示していたことです。これにより、ブラウザーは名前タグ (またはそのようなもの) を見つける方法を認識できませんでした。CSS から display:none を削除しました。

于 2010-10-21T16:19:18.713 に答える