如何在点击jquery上平滑滚动

时间:2014-11-09 17:52:06

标签: javascript jquery html scroll

我希望能够使用其id平滑滚动到特定div,但我当前的脚本不正确。任何人都可以看到我的错误在哪里?

这是我的小提琴,供参考here

    <script>
    $(document).ready(function() {
    $('a').click(function(){
    $('html, body').animate({
        scrollTop: $( $.attr(this, 'href') ).offset().top
    }, 5000);
    return false;
        });
        });
    </script> 

感谢。

1 个答案:

答案 0 :(得分:1)

无需在jsfiddle中添加脚本标记。尝试这个小提琴。 http://jsfiddle.net/wn6rv94t/1/ 移除<script></script>

相关问题