window.scrollTo is not working in mobile phones

我的未来我决定 提交于 2019-12-12 09:36:36

问题


on my mobile view of my webpage i can scroll in vertical and horizontal direction, but this starts always at the top left corner. Now i want to set the viewport to my custom position with window.scrollTo or something equivalent. window.scroll seem just to work for desktop browser.

any idea how i could solve that?


回答1:


I got it finally working.

i had to use additionally the setTimeout function

setTimeout(window.scrollTo(x,y),100);



回答2:


As I said in my comment, this works if your content is large enough. This means larger than the viewport. Without knowing specifics, did you look into setting the viewport meta tag?

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Now, if your content div or image or whatever exceeds the size of the viewport width (320 dips on iPhone) you can scroll on the x axis. The same is true for the y axis with different values though.



来源:https://stackoverflow.com/questions/11845371/window-scrollto-is-not-working-in-mobile-phones

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