从缩小的 Mobile Safari 浏览器获取文档宽度或窗口宽度

发布于 2024-11-27 10:40:52 字数 497 浏览 6 评论 0原文

我正在我们的网站上做一个基于 jquery 的灯箱,在主要的桌面操作系统浏览器上一切都很好。

但在 Mobile Safari(iPhone 和 iPad)上——可能还有 Android 设备上——由于这些浏览器的缩放功能而存在问题。

这是一个“普通”灯箱,插入一个覆盖元素并在该覆盖层上显示一些图像。

这就是我想做的: 我想覆盖整个窗口,因此我得到 $(window).width()$(window).height() 并将覆盖设置为这些值。

这在普通桌面浏览器上没问题,因为它们不会缩放,但在缩放设备上,它会导致覆盖层太窄太短,因为这些值是 768x946,而桌面上页面的实际宽度超过 1400 是的,

我可以关闭缩放功能,但该网站缩小后看起来很好,所以我想避免这种情况。

所以问题一定是: 当页面缩小时,如何获得窗口或主体元素的实际未缩放宽度?

先感谢您 :-) 马丁

I'm doing a jquery-based lightbox on our site, and all is well on the major desktop OS browsers.

But on Mobile Safari, (both iPhone and iPad) - and probably also on Android devices - there's an issue due to the scaling feature on these browsers.

It's a 'normal' lightbox that inserts an overlay element and shows some images on top of that overlay.

Here's what I'm trying to do:
I want to cover the entire window, so I get $(window).width() and $(window).height() and set the overlay to those values.

That's fine on normal desktop browsers, since they don't scale, but on scaling devices, it causes the overlay to be too narrow and too short, since those values are 768x946 and the actual width of the page on the desktop is over than 1400.

Yes, I could turn off scaling, but the site looks fine scaled down, so I would like to avoid that.

So the question must be:
How do you get the actual unscaled width of either the window or the body-element, when the page is scaled down?

Thank you in advance :-)
Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不弃不离 2024-12-04 10:40:52

您是否尝试过设置视口?
https://developer.mozilla.org/en/mobile/viewport_meta_tag

只是禁止缩放它应该工作的页面:P

Have you tried to set the viewport?
https://developer.mozilla.org/en/mobile/viewport_meta_tag

just forbid to zoom the page it should work :P

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文