iPad 不会触发从垂直到水平的调整大小事件?

发布于 2024-08-30 15:21:06 字数 437 浏览 4 评论 0原文

有人注意到这种行为吗?我正在尝试编写一个在调整大小时触发的脚本。它在普通浏览器上运行良好,在 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 技术交流群。

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

发布评论

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

评论(7

靑春怀旧 2024-09-06 15:21:06

如果我理解正确的话,你想要在用户倾斜 iPad 时执行某些操作。给你:

window.onorientationchange = function(){

    var orientation = window.orientation;

    // Look at the value of window.orientation:

    if (orientation === 0){

        // iPad is in Portrait mode.

    }

    else if (orientation === 90){

        // iPad is in Landscape mode. The screen is turned to the left.

    }


    else if (orientation === -90){

        // iPad is in Landscape mode. The screen is turned to the right.

    }

}

左图为纵向模式,右图为横向模式

If I understood you correctly, you want to do something when the user tilts the iPad. Here you go:

window.onorientationchange = function(){

    var orientation = window.orientation;

    // Look at the value of window.orientation:

    if (orientation === 0){

        // iPad is in Portrait mode.

    }

    else if (orientation === 90){

        // iPad is in Landscape mode. The screen is turned to the left.

    }


    else if (orientation === -90){

        // iPad is in Landscape mode. The screen is turned to the right.

    }

}

The left picture shows portrait mode, the right one landscape mode

会发光的星星闪亮亮i 2024-09-06 15:21:06

我认为你想要的是使用 iPad Orientation CSS,如下所示:

<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css" />
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css" />

另外,根据iPad Web 开发技巧

总之,这应该为您提供足够的工具来应对变化。

I think what you want would be to use the iPad Orientation CSS, which looks like this:

<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css" />
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css" />

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.

┈┾☆殇 2024-09-06 15:21:06

这包括所有方向。

这里有两个选择:

window.onorientationchange = function() {

    var orientation = window.orientation;

    // Look at the value of window.orientation:

    if (orientation === 0) {
    // iPad is in Portrait mode.

    } else if (orientation === 90) {
     // iPad is in Landscape mode. The screen is turned to the left.

    } else if (orientation === -90) {
     // iPad is in Landscape mode. The screen is turned to the right.

    } else if (orientation === 180) {
    // Upside down portrait.

    }
}    

或者

// Checks to see if the platform is strictly equal to iPad:
    if(navigator.platform === 'iPad') {
            window.onorientationchange = function() {

            var orientation = window.orientation;

            // Look at the value of window.orientation:

            if (orientation === 0) {
            // iPad is in Portrait mode.

            } else if (orientation === 90) {
             // iPad is in Landscape mode. The screen is turned to the left.

            } else if (orientation === -90) {
             // iPad is in Landscape mode. The screen is turned to the right.

            } else if (orientation === 180) {
            // Upside down portrait.

            }
          }       
        }

This includes all orientations.

Here are two options:

window.onorientationchange = function() {

    var orientation = window.orientation;

    // Look at the value of window.orientation:

    if (orientation === 0) {
    // iPad is in Portrait mode.

    } else if (orientation === 90) {
     // iPad is in Landscape mode. The screen is turned to the left.

    } else if (orientation === -90) {
     // iPad is in Landscape mode. The screen is turned to the right.

    } else if (orientation === 180) {
    // Upside down portrait.

    }
}    

or

// Checks to see if the platform is strictly equal to iPad:
    if(navigator.platform === 'iPad') {
            window.onorientationchange = function() {

            var orientation = window.orientation;

            // Look at the value of window.orientation:

            if (orientation === 0) {
            // iPad is in Portrait mode.

            } else if (orientation === 90) {
             // iPad is in Landscape mode. The screen is turned to the left.

            } else if (orientation === -90) {
             // iPad is in Landscape mode. The screen is turned to the right.

            } else if (orientation === 180) {
            // Upside down portrait.

            }
          }       
        }
九命猫 2024-09-06 15:21:06

我能从苹果找到的唯一东西

iPad 上的 Safari 和 iPhone 上的 Safari 没有可调整大小的窗口。在 iPhone 和 iPad 上的 Safari 中,窗口大小设置为屏幕大小(减去 Safari 用户界面控件),并且用户无法更改。要在网页上移动,用户可以通过双击或捏合来放大或缩小,或者通过触摸并拖动来平移页面来更改视口的缩放级别和位置。当用户更改视口的缩放级别和位置时,他们是在固定大小的可视内容区域(即窗口)内进行操作。这意味着位置“固定”到视口的网页元素最终可能会出现在可视内容区域之外、屏幕外。

我理解“适用于 iPhone”部分……但也许现在不再适用了?这可能是自最新公开 iPhone 操作系统版本发布以来操作系统/移动 Safari 的变化(上述文档来自 2010 年 3 月)。

我将重新标记这个问题,添加 iPhone,也许使用开发者 4.0 操作系统版本的人之一可以测试这个?如果是这样的话,它已经被删除了,这应该是一个在它上线之前提交/修复的错误……我不确定苹果的程序是如何的。

The only thing I could find from apple:

Safari on iPad and Safari on iPhone do not have resizable windows. In Safari on iPhone and iPad, the window size is set to the size of the screen (minus Safari user interface controls), and cannot be changed by the user. To move around a webpage, the user changes the zoom level and position of the viewport as they double tap or pinch to zoom in or out, or by touching and dragging to pan the page. As a user changes the zoom level and position of the viewport they are doing so within a viewable content area of fixed size (that is, the window). This means that webpage elements that have their position "fixed" to the viewport can end up outside the viewable content area, offscreen.

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.

不弃不离 2024-09-06 15:21:06

您希望修复 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.

寻找我们的幸福 2024-09-06 15:21:06

检查您的 iOS 版本。

“orientationchange”事件在 iOS 3.* 中不起作用,但在 4.* 中起作用

Check your version of iOS.

The "orientationchange" event does not work in iOS 3.*, but it does in 4.*

你列表最软的妹 2024-09-06 15:21:06
  1. 仔细检查您的平台是否为 iPad,
  2. 通过捕获 window.onorientationchange 处理 iOS 特定事件orientationchange

    if(navigator.platform == 'iPad') {
        window.onorientationchange = 函数() {
            // 处理方向改变事件
            //(这里你可以利用方向属性
            // - 请参阅上面 Vincent 的好答案)
        }       
    }
    
  1. do a nice check if your platform is iPad,
  2. handle the iOS specific event orientationchange by catching window.onorientationchange

    if(navigator.platform == 'iPad') {
        window.onorientationchange = function() {
            // handle orientationchange event
            // (here you can take advantage of the orientation property
            //     - see the good answer above by Vincent)
        }       
    }
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文