Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  36] [ 4]  / answers: 1 / hits: 17651  / 15 Years ago, sat, february 13, 2010, 12:00:00

I'm trying to position a div in the center of the iphone viewport.
Basically so that when you hit an image, it pops up in the middle of the screen regardless of where you had scrolled to on the page before you clicked.



It's not as simple as just making it position: fixed; as that will cause the origin to be the top of the page, not the top of the viewport.



I also can't do something like detecting scroll events and keeping a track of where I'm currently scrolled to, as the Javascript I'm writing is only injected into the page and executed when the popup is triggered.



Is there an iPhone specific JavaScript API or something I can use to get the current viewport coordinates?



Thanks,
Toby


More From » iphone

 Answers
25

Stupidly easy.



var scrollX = window.pageXOffset;
var scrollY = window.pageYOffset;


...gives you the current window position.


[#97581] Wednesday, February 10, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarkulisesa

Total Points: 422
Total Questions: 93
Total Answers: 112

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
clarkulisesa questions
Mon, Feb 24, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;