Jquery - Animated return to top of page when clicked

I want to animate the scroll effect so that the user can get to the top of the page when clicking on an element. A bit like snapping to the top of the page, but smoother.

I saw this (I do not remember where).

Does anyone know how to do this?

+4
source share
4 answers

You want the .animate() property of scrollTop to 0 , for example:

 $("html, body").animate({ scrollTop: 0 }, 500); 
+19
source

you can try the following:

  $('#somewhere').click(function(){ $('html, body').animate({scrollTop:0}, 'slow'); }); 
+2
source

You can put this code in a document download, for example, to animate up

 $("html, body").animate({ scrollTop: 0 }, 1000); 

And you can animate to a specific element, for example

 $("html, body").animate({ scrollTop: $('.my-element').offset().top }, 1000); 
0
source

I used the localscroll plugin for Ariel Flesler to do this many times ... http://demos.flesler.com/jquery/localScroll

-1
source

Source: https://habr.com/ru/post/1333188/


All Articles