如何在 iPad 中调整网页大小/重新缩放
我有一个网站,其移动版本使用 jquery mobile。当我将其从纵向更改为横向时,它会正确放大,但当我翻转到纵向时,它会保持相同的缩放级别,并且比视图更宽,这会破坏用户体验。 我使用常规:
<meta name="viewport" content="width=device-width, initial-scale=1">
从我所做的所有搜索来看,这应该可以。不幸的是它不适合我。
这是我的问题,我可以使用 onorientationchange 事件来触发页面大小的调整,我只是不知道如何去做。你能帮忙吗?
PS 网站在这里,如果您想看一下 http://tmg.dev.dakic.com/mobile谢谢
, 泽利科
I have a website that uses jquery mobile for it's mobile version. I have a problem when I am changing it from portrait to landscape it zooms in correctly, but when I flip to portrait, it stays same zoom level and is wider then the view which breaks user experience.
I use regular:
<meta name="viewport" content="width=device-width, initial-scale=1">
from all the search I did, this should do. Unfortunately it isn't working for me.
Here is my question, I can use onorientationchange event to trigger resizing of the page, I am just not sure how to go about it. Can you help please?
P.S. website is here if you would like to take a peek http://tmg.dev.dakic.com/mobile
Thank you,
Zeljko
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个,我遇到了类似的问题:
尝试在某些事件中使用 resize() 函数:
Try this, I had a similar issue:
Try otherwise using the resize() function at certain events:
我通常使用
orientationchange
事件向内容添加/删除 CSS 类,然后从那里开始,而不是重新调整视口的大小。苹果提供了一些独立的示例代码,尽管从记忆中我认为它只包括 90° 和 0° 方向 - 你也需要 -90° 和 180°,如 @zyrex 评论中所示。iPhoneOrientation 示例代码(developer.apple.com)
根据评论更新:
为了澄清,我不会重新调整 HTML 实体本身的大小,而是更改正在使用的类,并依赖 CSS 来相应地设置样式。举一个简单的例子,假设我想在
body
元素上的两个类之间切换,根据设备方向,我会在我的 Javascript 中执行类似的操作:... 以及类似的操作默认标记:
...然后 CSS 执行所需的操作 - 例如,body 元素的
背景
的不同位置:更新 #2
您可能还需要修改元标记中的
maximum-scale
指令。 Mobile Safari 通常在从纵向更改为横向时会进行缩放,而不是重新进行页面布局,这可能就是您所看到的。maximum-scale 值可以防止这种情况发生,但您应该注意,这也意味着用户无法执行正常的捏合缩放操作。标签的外观如下:
也请务必检查此处的答案:
如何在 iPhone 上更改方向时重置 Web 应用程序的比例/缩放?
I typically use the
orientationchange
event to add / remove CSS classes to the content, and go from there, rather than re-size the viewport. Apple provide some stand-alone example code, although from memory I think that it only includes 90° and 0° orientations—you need -90° and 180° too, as in @zyrex comment.iPhoneOrientation sample code (developer.apple.com)
Update per comment:
To clarify, I don't re-size HTML entities themselves, rather change the classes being used, and rely on CSS to style accordingly. To take a simplistic example, say I want to switch between two classes on the
body
element, depending on device orientation, I would do something like this in my Javascript:… and something like this in the default mark-up:
… and then CSS which does whatever is required—e.g. a different position for the body element's
background
:Update #2
You may also need to tinker with the
maximum-scale
directive in your meta tag. Mobile Safari typically does a zoom when changing from portrait to landscape, instead of re-doing the page layout, and that may be what you're seeing.The
maximum-scale
value prevents this, but you should note that this also means users can't do the normal pinch-to-zoom thing. Here's how the tag would look:Be sure to check the answers here too:
How do I reset the scale/zoom of a web app on an orientation change on the iPhone?
看来没人知道。据我所知,页面上某处的内容比设备宽度更宽,这就是问题的根源。然而,如何解决这个问题仍然不太清楚。
It seems no-one knows. From what I could see, content on the page somewhere is wider then device-width and this is where the problem originates. However, how to go about solving this is still not quite clear.