我正在使用代码锁定我的 html 应用程序页面之一的方向,但它似乎不起作用,请指导我缺少什么或修复它的方法
document.addEventListener("intel.xdk.device.ready", onDeviceReady, false);
function onDeviceReady(){
intel.xdk.device.setRotateOrientation('landscape');
console.log('heyy');
intel.xdk.device.hideSplashScreen();
}
在 hybridsapps 上强制一个特定的方向有点困难,因为你使用的是 titanium 或 cordova,或者你正在为 Android、iOs 或 Windows 开发。
我建议使用另一个视角:尝试使用 JavaScript 检测设备的方向(例如,在调整窗口大小时触发事件,并将高度与宽度进行比较),并显示警告,以便仅从 web 读取您想要的方向,或对网站主体应用 90 度变换以随设备旋转它。
另一个选择是为每个方向应用 CSS 样式。
function myFunction() {
var w = window.outerWidth;
var h = window.outerHeight;
var txt = "";
if (w < h) {
txt ="The windows is <b>PORTRAIT</b> mode";
} else if (h < w) {
txt ="The windows is <b>LANDSCAPE</b> mode";
} else {
txt ="The windows is <b>SQUARE</b> mode";
}
document.getElementById("demo").innerHTML = txt;
}
<body onresize="myFunction()" onload="myFunction()">
<p>Try to resize the browser window to emule the orientation change.</p>
<p id="demo"></p>
<p><strong>Note:</strong> this example will not work properly in IE8 and earlier. IE8 and earlier do not support the outerWidth/outerHeight propery of the window object.</p>
</body>
对不起我的英语。