Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll to top not working for safari

I am calling this javascript on page load

document.body.scrollTop = document.documentElement.scrollTop = 0;

I want html page starts from top when loaded, above javascript working fine for chrome, safari(macbook) but not working for safari on iphone, can anybody suggest workaround in javascript only.

like image 423
Lalji Gajera Avatar asked Nov 08 '22 06:11

Lalji Gajera


1 Answers

Posting this here for future visitors from Google. This same error occured to me... The problem was just one CSS rule on body element.

overflow-x: hidden

If this CSS rule exists, remove it and scrollTop should work on mobile Safari.

like image 66
Skosh Avatar answered Nov 14 '22 22:11

Skosh