获取移动(iPhone)Safari中视口的当前位置 [英] Get current position of the viewport in Mobile (iPhone) Safari

查看:147
本文介绍了获取移动(iPhone)Safari中视口的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将div放在iphone视口的中心。
基本上这样当你点击图像时,无论你在点击之前在页面上滚动到哪里,它都会弹出屏幕中间。

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.

我也无法做类似于检测滚动事件和保持跟踪我当前滚动到的位置,因为我正在编写的Javascript仅被注入页面并在触发弹出窗口时执行。

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.

是否有iPhone我可以使用特定的JavaScript API来获取当前的视口坐标吗?

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

谢谢,
托比

推荐答案

愚蠢容易。

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

...给出当前窗口位置。

...gives you the current window position.

这篇关于获取移动(iPhone)Safari中视口的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆