Safari iPhone - 如何检测缩放级别和偏移? [英] Safari iPhone - How to detect zoom level and offset?
问题描述
我在iPhone上的Safari中查看如何在页面上跟踪用户缩放和平移的选项。 Safari暴露了移动和手势事件,所以理论上我可以保持平移和缩放操作的运行记录,但这似乎有点过分,因为浏览器必须在内部跟踪。
I looking for options on how to track user zooming and panning on a page when viewed in Safari on an iPhone. Safari exposes move and gesture events, so theoretically I can keep a running tally of pan and zoom operations, but that seems like overkill since the browser must track that internally.
是通过文档对象模型公开此信息?
Is this information exposed through the Document Object Model?
推荐答案
放大时, window.innerWidth
已调整,但 document.documentElement.clientWidth
不是,因此:
When you zoom in, window.innerWidth
is adjusted, but document.documentElement.clientWidth
is not, therefore:
var zoom = document.documentElement.clientWidth / window.innerWidth;
(我测试了iOS4,没有 viewport
< meta>
)。
(I've tested iOS4, without viewport
<meta>
).
然而,我不会依赖它来做任何重要事情。移动浏览器中的DOM视口大小/像素大小完全混乱。
However, I wouldn't rely on it for anything important. DOM viewport sizes/pixel sizes in mobile browsers are a complete mess.
这篇关于Safari iPhone - 如何检测缩放级别和偏移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!