i'm trying to force the page to scroll to top on refresh with something similar to this
$(window).scrollTop(0);
But it seems to happen before the automatic scroll down on refresh. My script runs and then the browser restores its last position.
I'm running the code in several places like this
$(function(){
$(window).scrollTop(0);
});
$(window).scrollTop(0);
$(document).ready(function(){
$(window).scrollTop(0);
});
$(window).on('load',function(){
$(window).scrollTop(0);
});
BUt the same happens all the time. Do I have to put this code somewhere else? Load the JS in a specific part of the HTML? Is there anything else on pure JS or jQuery that could help me with this issue?
@Edit
I tried with $(html, body).scrollTo(0) and couldnt make it work
I tried without jQuery and nothing happened
window.scrollTo(0,0)
I disabled everything I had written with Javascript and put only this piece of code and nothing happens.
@edit2
I've had this problem before and I'm sure i 'solved' this with a setTimeout, as suggested by @raam86. The problem is that I do some math when page loads and this must be done before the user starts scrolling up and down
Aucun commentaire:
Enregistrer un commentaire