简体   繁体   English

检测 iphone/ipad 方向不起作用

[英]detecting iphone/ipad orientation not working

I have this simple script:我有这个简单的脚本:

function orientation() {

  var orientation = window.orientation;
  switch(orientation) {

    case 0:
       alert('0');

         break;

    case 90:
    alert('90');
        break;

    case -90:
    alert('-90');
         break;
  }
}   
$(document).ready(function(){
    window.onorientationchange = orientation();
})

but somehow I never get an alert on my ipad when I turn it... Have I made a mistake somewhere?但不知何故,当我转动它时,我从未在 ipad 上收到警报……我在某个地方犯了错误吗? Thanks for your help guys:).谢谢你们的帮助:)。

Here:这里:

window.onorientationchange = orientation;

You need to assign the function itself not the result of its execution.您需要分配 function 本身而不是其执行结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM