Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.scrollTo is not working in mobile phones

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?

like image 224
Safari Avatar asked Aug 07 '12 11:08

Safari


2 Answers

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.

like image 72
Torsten Walter Avatar answered Sep 18 '22 12:09

Torsten Walter


I got it finally working.

i had to use additionally the setTimeout function

setTimeout(window.scrollTo(x,y),100);
like image 25
Safari Avatar answered Nov 15 '22 06:11

Safari