本文介绍了如何找到(在javascript中)当前的“滚动”按钮。移动safari / iphone中的偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道用户在iphone上的移动版游戏中在视口内滚动了多远的x / y偏移量。

I'd like to know the x/y offset of the how far the user has "scrolled" within the viewport in mobile safari on the iphone.

Put换句话说,如果我(通过javascript)重新加载当前页面,我想找到我需要传递给window.scrollTo(...)的值,以便重新定位当前的文档/视口。

Put another way, if I (through javascript) reloaded the current page, I'd like to find the values I'd need to pass into window.scrollTo(...) in order to reposition the document/viewport as it is currently.

window.pageXOffset总是报告0

window.pageXOffset always reports 0

jquery的$('body')。scrollTop()总是报告0

jquery's $('body').scrollTop() always reports 0

事件有一个pageX,但如果您的手势是轻弹页面,这将不会解释您松开手指后发生的页面滚动/下。也就是说,当手指离开屏幕时它会给我一个点,但这并不总是与页面在完成滚动后的位置相匹配。

events have a pageX, but this won't account for the scrolling of the page that happens after you release your finger if your gesture was to "flick" the page up/down. Namely, it'll give me a point when the finger leaves the screen, but that doesn't always match where the page will be after it's finished scrolling.

任何指针?

推荐答案

window.pageYOffset 应该为您提供当前的滚动偏移量。如果你需要它还有 window.pageXOffset

window.pageYOffset should give you the current scroll offset. There's window.pageXOffset if you need it too.

这篇关于如何找到(在javascript中)当前的“滚动”按钮。移动safari / iphone中的偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:17