Automatically scroll up when loading page using jQuery

I am trying to use jQuery to automatically scroll up a page when a page loads. Here is my code:

<script type="text/javascript"> $(document).ready(function () { $(window).scrollTop(0); return false; }); </script> 

However, the code does not work. I also tried replacing $(window) with $('html, body') , unfortunately this still doesn't work.

So can anyone advise this? Thank you very much!

+4
source share
4 answers

try it

 <script type="text/javascript"> $(document).ready(function () { window.scrollTo(0,0); }); </script> 

Parameters 0,0 are the x and y coordinates.

Hope this helps.

+9
source

The above solutions did not work for me in Chrome. It was with this that I achieved the greatest success:

 $(window).on('beforeunload', function() { $('body').fadeOut(225); }); 
+1
source

Easier and more reliable if you use this solution:

 <script type="text/javascript"> $('html,body').animate({scrollTop:0},800); </script> 

In fact, some browsers will respond to 'html' and some to 'body' .

PS. "800" is the duration of the animation.

0
source

This is jQuery safe:

 < script > $(window).scrollTop(0); </script> 
0
source

All Articles