0

我在实现 scrollTo 时遇到问题。

<div id="container">    
        <section class="rcWrapper">
            <ul>
                <li class="slide" id="slide-1">1</li>
                <li class="slide" id="slide-2">2</li>
                <li class="slide" id="slide-3">3</li>
                <li class="slide" id="slide-4">4</li>
                <li class="slide" id="slide-5">5</li>
            </ul>
        </section>

        <nav id="navigation">
            <a href="#slide-1">slide-1</a>
            <a href="#slide-2">slide-2</a>
            <a href="#slide-3">slide-3</a>
            <a href="#slide-4">slide-4</a>
            <a href="#slide-5">slide-5</a>
        </nav>
    </div><!-- end of container -->

这是我的js:

$(function(){
    $('#navigation a:first-child').click(function(){
        $(window).scrollTo('#slide-1', 800);
    });
});

我可能错过了一些东西,但我看不到它。任何人??谢谢!

4

2 回答 2

0
   .click(function(){    
     $(window).animate({
        scrollTop: $('#slide-1').offset().top,
        // scrollLeft: $('#slide-1').offset().left
     }, 1000);
     return false; // <- don't forget about this line, because if it won't be there, browser will follow link.
   });
于 2013-09-16T11:11:34.970 回答
0

不用 JS 代码试试。

<div id="container">    
    <section class="rcWrapper">
        <ul>
            <li class="slide" id="slide-1">1</li>
            <li class="slide" id="slide-2">2</li>
            <li class="slide" id="slide-3">3</li>
            <li class="slide" id="slide-4">4</li>
            <li class="slide" id="slide-5">5</li>
        </ul>
    </section>

    <nav id="navigation">
        <a href="#slide-1">slide-1</a>
        <a href="#slide-2">slide-2</a>
        <a href="#slide-3">slide-3</a>
        <a href="#slide-4">slide-4</a>
        <a href="#slide-5">slide-5</a>
    </nav>
</div><!-- end of container -->

属性 href = "id_element"

于 2013-09-16T11:15:32.847 回答