android 3.0: JS scrollTop not working on chrome/webview

╄→尐↘猪︶ㄣ 提交于 2019-12-12 09:58:00

问题


I've written an app wrap by a webView, it work as expected on my milestone2 2.2
but the scrolling functions is not working on 3.0's chrome(work in FF)
neither by dom.scrollTop = XXX nor jquery $("#id").scrollTop(X)
is it a bug? anyone can suggest how I fix it, thx!

my tablet is Acer ICONIA TAB A500 with Android 3.0.1


回答1:


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!




回答2:


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?



来源:https://stackoverflow.com/questions/6208883/android-3-0-js-scrolltop-not-working-on-chrome-webview

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