iPad 不会触发从垂直到水平的调整大小事件?
有人注意到这种行为吗?我正在尝试编写一个在调整大小时触发的脚本。它在普通浏览器上运行良好,在 iPhone 上运行良好,但在 iPad 上,只会触发从水平到垂直视口,反之亦然。
这是代码:
$(window).resize( function() {
var agent=navigator.userAgent.toLowerCase();
var is_iphone = ((agent.indexOf('iphone') != -1));
var is_ipad = ((agent.indexOf('ipad') != -1));
if(is_iphone || is_ipad){
location.reload(true);
} else {
/* Do stuff. */
};
});
Has anyone noticed this behavior? I'm trying to write a script that will trigger upon a resize. It works fine on normal browsers, works fine on iPhone, but on iPad, will only trigger going from horizontal to vertical viewport, not vice versa.
Here's the code:
$(window).resize( function() {
var agent=navigator.userAgent.toLowerCase();
var is_iphone = ((agent.indexOf('iphone') != -1));
var is_ipad = ((agent.indexOf('ipad') != -1));
if(is_iphone || is_ipad){
location.reload(true);
} else {
/* Do stuff. */
};
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果我理解正确的话,你想要在用户倾斜 iPad 时执行某些操作。给你:
If I understood you correctly, you want to do something when the user tilts the iPad. Here you go:
我认为你想要的是使用 iPad Orientation CSS,如下所示:
另外,根据iPad Web 开发技巧。
总之,这应该为您提供足够的工具来应对变化。
I think what you want would be to use the iPad Orientation CSS, which looks like this:
Also, the
orientationchange
event fires when the orientation is changed, according to iPad web development tips.Together, that should give you tools enough to deal with the change.
这包括所有方向。
这里有两个选择:
或者
This includes all orientations.
Here are two options:
or
我能从苹果找到的唯一东西:
我理解“适用于 iPhone”部分……但也许现在不再适用了?这可能是自最新公开 iPhone 操作系统版本发布以来操作系统/移动 Safari 的变化(上述文档来自 2010 年 3 月)。
我将重新标记这个问题,添加 iPhone,也许使用开发者 4.0 操作系统版本的人之一可以测试这个?如果是这样的话,它已经被删除了,这应该是一个在它上线之前提交/修复的错误……我不确定苹果的程序是如何的。
The only thing I could find from apple:
I understand the "works on the iPhone" part...but maybe it doesn't anymore? This could be a change in OS/mobile Safari since the latest public iPhone OS release shipped (the above documentation is from March 2010).
I'm going to re-tag this question adding iPhone to it, maybe one of the guys with the developer 4.0 OS release can test this? If it is the case it's been removed, this should be a bug filed/fixed before it goes live...I'm not sure on how the procedures are on this with Apple are though.
您希望修复 iPhone 和 iPad 上的方向错误。
在这里阅读:
http://www.blog。 highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
github 最新版本在这里:
https://gist.github.com/901295
使用页面上的第二个版本。
You want this fix for the orientation bug on iphone and ipad.
read about it here:
http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
github newest version here:
https://gist.github.com/901295
use the second version on the page.
检查您的 iOS 版本。
“orientationchange”事件在 iOS 3.* 中不起作用,但在 4.* 中起作用
Check your version of iOS.
The "orientationchange" event does not work in iOS 3.*, but it does in 4.*
通过捕获 window.onorientationchange 处理 iOS 特定事件orientationchange
handle the iOS specific event orientationchange by catching window.onorientationchange