get viewport position in javascript in iphone safari

Go To StackoverFlow.com

2

I'm trying to prevent element from scrolling in safari on iphone. I've tried solutions mentioned here: iPhone Safari: Scroll a list inside a html container But my list is large and it doesn't work so smoothly.

What I have in mind is to detect onscroll event and reposition the element, so it's in the boundaries of viewport.

But I can't find way to detect coordinates of the viewport. Can anybody help with this?

Thanks.

2009-06-16 18:22
by Bogdan Kanivets


0

document.addEventListener(
    'touchmove',
    function touchMove(event) {
        event.preventDefault()
    },
    false
);
2009-08-26 12:45
by NoName
I think you may also need event.stopPropagation( - Kevin Hakanson 2010-06-02 19:15


0

Take a look at iScroll. If is doesn't do what you want, you can use the implementation for reference. I think the trick so to do both event.preventDefault() and event.stopPropagation() to keep mobile safari from responding to the touch events.

iScroll was born because mobile webkit (on iPhone, iPod, Android and Pre) does not provide a native way to scroll content inside a fixed width/height element. This unfortunate situation prevents any web-app to have a position:absolute header and/or footer and a scrolling central area for contents.

2010-06-02 19:15
by Kevin Hakanson


0

var viewport_x = window.pageXOffset;
var viewport_y = window.pageYOffset;
2011-04-06 10:28
by marramgrass
This should be window.pageXOffset and window.pageYOffsetShadow Wizard 2011-06-27 08:00
Ads