android 3.0: JS scrollTop not working on chrome/webview

本秂侑毒 提交于 2019-12-06 09:50:20

I've experienced a similar deficiency in Android browser. The way I worked around this problem was to use $(window).scrollTop(x); or window.scrollTo(x,0);

The reason this works is that scrollTo is usually supported in Android browser for the window even when scrollTo is not supported for divs. I was able to restructure my CSS using "position:fixed" so that the body scrolled with my content and all other components were fixed. After this, everything worked perfectly!

Allan Nienhuis

A workaound that worked for me: first, temporarily set the overflow property to 'hidden', then set the scrollTop property, then set the overflow property back to 'scroll' (or auto). The scrollTop value seems to be kept intact and honored when the overflow property is set back to 'scroll'. This was a pretty trivial workaround that worked on all browsers I tested on (desktop and mobile). I didn't test it exhaustively, and I didn't test with transitions in place, so there may be side-effects that I haven't encountered... Your mileage may vary - but it's an easy thing to try. see: jQuery scrollTop() does not work in scrolling DIV on mobile browsers, alternatives?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!