If write this:
$(document).on("click", function () {
window.scroll( 0, 70 );
});
works always, but if write this:
window.onload = function () {
window.scroll( 0, 70 );
}
this not works in safari and in “incognito window” for chrome. in other browsers works.
why?
In very simple terms, the main reason is the state of the different browser/dom elements you are binding to.
In the first one, you are binding to the
clickevent on the<body/>using jQuery, which is possibly ensuring that by the time you get around to actually clicking it, thebodyof the document is initialised and has enough scroll left to make the effect appear to you.In the second one, you are binding to the
onloadevent of the window, which actually fires much before thebodymay have loaded, or accumulated enough scrollable area, thus making the effect to not appear.The ideal technique instead would be to use