0

私は水平レイアウトで作業しており、jquery を使用してアンカーをクリックすると、html セクションをナビゲートしようとしています。クリックすると次のセクションにジャンプします。

同じことを垂直に行っている例がいくつかあります。

HTML コード:

<div id="main">
    <div id="nav">
        <a id="prev" class="prev"> prev </a>
            <a id="next" class="next"> next </a>
        </div>
        <div class="content-container">
        <div class="content">
            <section id="about" class="panel">

                <p>About content</p>

            </section><!-- end about -->

            <section id="event" class="panel">

                <p>Event content</p>                

            </section><!-- end event -->

            <section id="services" class="panel">

                <p>Services content</p>

            </section><!-- end services -->

        </div><!-- end content -->

    </div><!-- end content-container -->
</div><!-- end main -->

JS コード

<script src="jquery-1.6.min.js"></script>
<script type="text/javascript">

    function scrollToPosition(element) {
            if (element !== undefined) {
                $("#main.content-container").scrollTo(element, 700, {
                    margin: true
                });
            }
    }

    $(function() {

            var posts = $('.panel');
        var position = 0; //Start Position
            var next = $('#next');
            var prev = $('#prev').hide();

            next.click(function(evt) {

                prev.show();
                scrollToPosition(posts[position += 1]);
                if (position === posts.length - 1) {
                        next.hide();
                }
            });

            prev.click(function(evt) {
                next.show();
                scrollToPosition(posts[position -= 1]);
                if (position === 0) {
                        prev.hide();
                }
            });

    });
</script>

私は何を間違っていますか?

4

1 に答える 1

1

scrollTojQuery メソッドではなく、プラグイン メソッドを使用しています。プラグインが含まれていないため、コードはブラウザー コンソールでエラーをスローし、何もしません。

jQuery.js をロードした後、コードの前にプラグイン ファイルを含めます。

そうしないと、css が動作しているのを見なければ、他にどのような問題があるかを判断するのが難しくなります。

于 2013-02-07T00:06:27.880 に答える