anoonimo anoonimo - 1 year ago 53
Javascript Question

ScrollTop on page reload doesn't work (possible script conflict)

I'm working on this page

I added this to make it scroll to the top when someone refreshes the page but doesn't seem to work, I wonder if it's a conflict with the other scrolling scripts I'm using.

<script type="text/javascript">

Any clue?

P.s.: work in progress: messy scripts


Try this:

$(document).ready(function() {
  $("html,body").animate({scrollTop: 0}, 100); //100ms for example

Or this:

window.onload = function() {
 setTimeout (function () {
 }, 100); //100ms for example

Or this:

$(window).on('beforeunload', function() {

Browsers tend to jump back to their last scroll position on a reload, which makes sense in many cases. It seems that this automatic jump gets triggered right after the onload event (but we don't know the exact moment when this happens), so it makes sense to either use some delay, or have the browser scroll to the top before the page reloads ;)