Harry
Harry

Reputation: 782

Making window.scrollTo() physically scroll to a certain point

I am using the window.scrollTo(); method on a button click. But, when I click the button, it just jumps to the position. I want it to physically display the scrolling to the position of the window. How can I do this?

Upvotes: 2

Views: 702

Answers (1)

silversunhunter
silversunhunter

Reputation: 1269

Jquery is the best answer for this. It makes it really simple

$('html, body').animate({
    scrollTop: $(".the_div_you_want_to_got_to").offset().top
 }, 1750);

If you have not used Jquery before, it is a javascript extension. You will need to include it in the head of your doc

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Upvotes: 1

Related Questions