gpt4 book ai didi

javascript - 音隙方向变化

转载 作者:行者123 更新时间:2023-11-28 10:08:41 24 4
gpt4 key购买 nike

window.onresize = function(){ updateOrientation(e); }
function updateOrientation(e) {
alert("hey");

deviceWidth = $('body').width();
if (deviceWidth == 320) {
currentOrientation = "portrait";
}
else if (deviceWidth == 480) {
currentOrientation = "landscape";
}

// fire a function that checks the orientation every x milliseconds
setInterval(checkOrientation, 500);

// check orientation
function checkOrientation() {
deviceWidth = $('body').width();
if (deviceWidth >= '1200') {
newOrientation = "portrait";
}
else if (deviceWidth <= '900') {
newOrientation = "landscape";
}
// if orientation changed since last check, fire either the portrait or landscape function
if (newOrientation != currentOrientation) {
if (newOrientation == "portrait") {
changedToPortrait();
}
else if (newOrientation == "landscape") {
changedToLandscape();
}
currentOrientation = newOrientation;
}
}

// landscape stuff
function changedToLandscape() {
alert('Orientation has changed to Landscape!');
}

// portrait stuff
function changedToPortrait() {
alert('Orientation has changed to Portrait!');
}
}

我正在使用它来使用phonegap检测Android平板电脑中的方向变化。不知怎的,代码不起作用。有什么建议么?我猜测它无法生成方向改变事件。

最佳答案

这对我在 PhoneGap 中有用:

function onOrientationChange() {
switch (window.orientation) {
case -90:
case 90:
alert('landscape');
break;
default:
alert('portrait');
break;
}
};
window.onresize = onOrientationChange;

关于javascript - 音隙方向变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7803578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com