Anfa A
Anfa A

Reputation: 313

How to smooth scroll on click jquery

I want to be able to smooth scroll to a specific div using its id but my current script isn't correct. Can anyone see where my error is?

Here is my fiddle for reference here.

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

Thanks.

Upvotes: 0

Views: 63

Answers (1)

Ninja
Ninja

Reputation: 2098

no need to add script tag in jsfiddle. Try with this fiddle. http://jsfiddle.net/wn6rv94t/1/ Removed<script></script>

Upvotes: 1

Related Questions